home *** CD-ROM | disk | FTP | other *** search
/ Saar AMOK 2 / Saar AMOK II - Oktober 1994 (1994)(Kreativ Marketing)(DE)[!][I-7598].iso / tools / muchmore / src / muchmore.mod next >
Text File  |  1994-06-19  |  93KB  |  2,815 lines

  1. (*---------------------------------------------------------------------------
  2. :Program.    MuchMore.mod
  3. :Author.     Fridtjof Siebert
  4. :Address.    Nobileweg 67, D-70439 Stuttgart, Germany
  5. :Shortcut.   [fbs]
  6. :Copyright.  Freeware
  7. :Language.   Oberon-2
  8. :Translator. Amiga Oberon Compiler v3.10
  9. :History.   V1.0 summer-88: First very slow internal version             [fbs]
  10. :History.   V1.1 24-Sep-88: First published version                      [fbs]
  11. :History.   V1.2 26-Nov-88: Now displays Filelength & Percentage         [fbs]
  12. :History.        27-Nov-88: Mouse can be used instead of Space/BackSpace [fbs]
  13. :History.   V1.3 29-Apr-89: Strong increase in speed, removed WarpText   [fbs]
  14. :History.        29-Apr-89: Now supports Numeric Keys (Home,PgUp etc.)   [fbs]
  15. :History.        29-Apr-89: Now opens Screen as big as gfx.normalDisplay [fbs]
  16. :History.   V1.4 29/30-Apr-89: Asynchronus loading/displaying. Very nice [fbs]
  17. :History.        30-Apr-89, 00:33: Removed bugs in Filelength & L-Command[fbs]
  18. :History.        30-Apr-89, 02:21: Added Find-Command                    [fbs]
  19. :History.        30-Apr-89, 10:30: Scrolling stops when window inactive  [fbs]
  20. :History.        01-May-89: Allocates no more unneeded memory for text   [fbs]
  21. :History.        07-May-89: Allocates even less memory now               [fbs]
  22. :History.        14-May-89: Removed deadlock-bug with Find-Window        [fbs]
  23. :History.   V1.5 25-May-89: Added print feature                          [fbs]
  24. :History.        25-May-89: Removed all imports (apart from Arts)        [fbs]
  25. :History.        26-May-89: inspired by J. Kupfer, I added nk 5 to quit  [fbs]
  26. :History.        26-May-89: Now handle BS correctly                      [fbs]
  27. :History.   V1.6 02-Jul-89: Now supports several fontstyles and colors   [fbs]
  28. :History.   V1.7 03-Jul-89: Is again as fast as it was with 2 colors     [fbs]
  29. :History.        03-Jul-89: Now no more crashes when quitting while print[fbs]
  30. :History.        07-Jul-89: removed bug with texts of length 0           [fbs]
  31. :History.   V1.8 10-Jul-89: small bug in find-command removed            [fbs]
  32. :History.        10-Jul-89: now found strings are highlighted            [fbs]
  33. :History.        14-Jul-89: nk0 to display fileinfo                      [fbs]
  34. :History.   V2.0 06-Aug-89: Ported this to OBERON                        [fbs]
  35. :History.        06-Aug-89: Added ARP-FileRequester                      [fbs]
  36. :History.        07-Aug-89: Added L - (load new file) Command            [fbs]
  37. :History.   V2.1 03-Sep-89: no more gurus if an r/w error occures        [fbs]
  38. :History.        03-Sep-89: MM used to execute CSI-Codes backwards. fixed[fbs]
  39. :History.        03-Sep-89: ping / pong with Shift+Fn / Fn               [fbs]
  40. :History.        03-Sep-89: new command: goto                            [fbs]
  41. :History.   V2.2 05-Sep-89: will run with any keymapping now             [fbs]
  42. :History.   V2.3 17-Sep-89: New command: sleep & Pop-Up feature          [fbs]
  43. :History.        17-Sep-89: "MuchMore -s" will go to sleep immediately   [fbs]
  44. :History.        17-Sep-89: Interprets <CSI>m as <CSI>0m now             [fbs]
  45. :History.   V2.4 17-Sep-89: New command: write block "w"                 [fbs]
  46. :History.        17-Sep-89: rewritten argument parser to allow quotes    [fbs]
  47. :History.   V2.5 18-Sep-89: now uses the 8x8 font set with SetFont       [fbs]
  48. :History.        19-Sep-89: no more scatters memory. Allocates 4K Chunks [fbs]
  49. :History.   V2.6 26-Jun-90: Made MuchMore reentrant                      [fbs]
  50. :History.        26-Jun-90: Opens 1-Plane Screen if memory is rare       [fbs]
  51. :History.        26-Jun-90: Asynchronus fast scrolling with Ctrl-Up/Down [fbs]
  52. :History.        26-Jun-90: Now supports interlaced screens              [fbs]
  53. :History.        08-Aug-90: CLI-Option '-l' to toggle interlaced mode    [fbs]
  54. :History.   V2.7 09-Aug-90: no more RethinkDisplay()s,looks good with 2.0[fbs]
  55. :History.        10-Aug-90: Supports Kick2.0 ASL-FileRequester           [fbs]
  56. :History.   V2.8 26-Dez-90: Leaves space between lines on interl. scrns  [fbs]
  57. :History.   V3.0 04-Jul-91: Supports any non-proportional font now       [fbs]
  58. :History.        04-Jul-91: no more supports '-s' (sleep),was rarely used[fbs]
  59. :History.        04-Jul-91: new Options -f<font> and -s<size> for font   [fbs]
  60. :History.        09-Nov-91: Find works w/ dmouse(window may get inactive)[fbs]
  61. :History.   V3.1 04-Sep-92: Uses Screenmode of Workbench screen          [fbs]
  62. :History.   V3.2 02-Nov-92: Supports non-scrollable screens              [fbs]
  63. :History.        02-Nov-92: Complete redraw doesn't scroll anymore       [fbs]
  64. :History. V3.2.1 24-Dec-92: XPK Support                             (C.Stiens)
  65. :History.        24-Dec-92: New option -p for Password              (C.Stiens)
  66. :History.        24-Dec-92: New option -e for Extra Spacing         (C.Stiens)
  67. :History.        24-Dec-92: New option -c for Screen Colors         (C.Stiens)
  68. :History.        24-Dec-92: Tooltypes                               (C.Stiens)
  69. :History. V3.2.2 08-Jan-93: Doesn't use MyMakeScreen() no more      (C.Stiens)
  70. :History. V3.2.3 08-Feb-93: Now closes Console Device               (C.Stiens)
  71. :History.        08-Feb-93: Non-Scroll Mode didn't work always      (C.Stiens)
  72. :History.        10-Feb-93: ScreenMode Requester                    (C.Stiens)
  73. :History.        10-Feb-93: New Option -s for Scroll Mode           (C.Stiens)
  74. :History.        10-Feb-93: Busy Pointer                            (C.Stiens)
  75. :History.        14-Feb-93: Now evals Tooltypes also on CLI start   (C.Stiens)
  76. :History. V3.2.4 15-Feb-93: Clears Idcmp while Busy                 (C.Stiens)
  77. :History.        15-Feb-93: Bugs in GetString fixed                 (C.Stiens)
  78. :History.        19-Feb-93: More Scrollmodes                        (C.Stiens)
  79. :History.        20-Feb-93: Bug in Type() fixed                     (C.Stiens)
  80. :History. V3.2.5 08-Mar-93: Asynch Scrolling changed                (C.Stiens)
  81. :History.        08-Mar-93: New Option -t for Taskpri               (C.Stiens)
  82. :History.        10-Mar-93: Now uses Dos.ReadArgs if KS 2.04        (C.Stiens)
  83. :History. V3.2.6 19-Mar-93: scrollmode 3 now also scrolls soft      (C.Stiens)
  84. :History.        19-Mar-93: New Option -o for one plane             (C.Stiens)
  85. :History.        19-Mar-93: New Option -a for tab width             (C.Stiens)
  86. :History.        19-Mar-93: Removed QText                           (C.Stiens)
  87. :History.        21-Mar-93: Opens screen with full overscan width   (C.Stiens)
  88. :History.        22-Mar-93: Filename can be on any pos at KS1.3     (C.Stiens)
  89. :History.        27-Mar-93: New Option N=NOOSCAN                    (C.Stiens)
  90. :History. V3.2.7 07-Apr-93: Dont pokes to bitmap no more            (C.Stiens)
  91. :History. V3.2.8 12-Apr-93: New Option B=PLANES                     (C.Stiens)
  92. :History. V3.2.9 12-May-93: Implemented V36 ANSI Codes              (C.Stiens)
  93. :History. 3.2.10 16-May-93: Locale Support                          (C.Stiens)
  94. :History.        16-May-93: DispMode-Requester font-sensitive       (C.Stiens)
  95. :History.   V3.3 21-Jun-93: Code optimised                          (C.Stiens)
  96. :History.        25-Jun-93: Safe quit                               (C.Stiens)
  97. :History.   V3.4 29-Jun-93: Clipboard support                       (C.Stiens)
  98. :History.        29-Jun-93: took version number out of catalog      (C.Stiens)
  99. :History.   V3.5 31-Jul-93: case sensitive search, Boyer-Moore Alg. (C.Stiens)
  100. :History.   V3.6 15-Aug-93: Page up/down with softscroll reimpl.    (C.Stiens)
  101. :History.        16-Aug-93: Flash at EOF/BOF                        (C.Stiens)
  102. :History.   V3.7 28-Oct-93: New option E=EDITOR                     (C.Stiens)
  103. :History.        21-Nov-93: MM was not 100% pure (BusyPointer)      (C.Stiens)
  104. :History.        21-Nov-93: Password has to be entered in stringgad (C.Stiens)
  105. :History.   V4.0 07-Dec-93: MM can run in a WB Window               (C.Stiens)
  106. :History.        07-Dec-93: Options WINDOW, LEFT, TOP, WIDTH, HEIGHT(C.Stiens)
  107. :History.        07-Dec-93: Kick 1.3 is no more supported           (C.Stiens)
  108. :History.        07-Dec-93: Removed Options SCROLLMODE and NOOSCAN  (C.Stiens)
  109. :History.   V4.1 05-Jan-94: Prefs BusyPointer, set rp.mask or MaxPen(C.Stiens)
  110. :History.        10-Jan-94: Pipe Support, new option PUBSCREEN      (C.Stiens)
  111. :History.        12-Jan-94: Option SCROLLMODE reintroduced          (C.Stiens)
  112. :History.        12-Jan-94: New Option I=INTERLEAVED                (C.Stiens)
  113. :History.   V4.2 29-Jan-94: Zoom Gadget (v39)                       (C.Stiens)
  114. :History.        29-Jan-94: Better test for Pipe                    (C.Stiens)
  115. :History.        30-Jan-94: Icon is found if MM is started w/path   (C.Stiens)
  116. :History.        31-Jan-94: New option FASTQUIT                     (C.Stiens)
  117. :History.        31-Jan-94: ShowTask allocates his signals now      (C.Stiens)
  118. :History.   V4.3 06-Mar-94: Change rp.mask only if necessary        (C.Stiens)
  119. :History.        16-Mar-94: New options: FRWIDTH, FRHEIGHT          (C.Stiens)
  120. :History.        20-Mar-94: Hide password when entering             (C.Stiens)
  121. :History.   V4.4 17-Jun-94: Bug in task sync fixed                  (C.Stiens)
  122. :History.        17-Jun-94: Uses ASL ScreenMode Requester now       (C.Stiens)
  123. :Contents.   A Soft-Scrolling ASCII-File Viewer.
  124. :Remark.     Compile: 'Oberon -svbcrntzdma MuchMore' for short code
  125. :Remark.     Compile: 'Oberon -dma MuchMore' for safe code
  126. :Remark.     Link:    'OLink -dma MuchMore'
  127. ---------------------------------------------------------------------------*)
  128.  
  129. MODULE MuchMore; (* $StackChk- *)
  130.  
  131. IMPORT loc:= Locale,
  132.        ip := IFFParse,
  133.        u  := Utility,
  134.        con:= Console,
  135.        str:= Strings,
  136.        ie := InputEvent,
  137.        I  := Intuition,
  138.        g  := Graphics,
  139.        d  := Dos,
  140.        e  := Exec,
  141.        ol := OberonLib,
  142. (* $IF quiet *) NoRequesters, (* $END *)
  143.        SYS:= SYSTEM;
  144.  
  145.  
  146. CONST
  147.   MuchText = "MuchMore 4.4 © 1988-94 AMOK\o$VER: muchmore 4.4 (19.6.94)";
  148.   Version = "v4.4";
  149.  
  150.   MSGOOM        = 0;
  151.   MSGCOS        = 1;
  152.   MSGCOW        = 2;
  153.   MSGCOF        = 3;
  154.   MSGRWERR      = 4;
  155.   MSGRETRYABORT = 5;
  156.   MSGEMPTY      = 6;
  157.   MSGSAVE       = 7;
  158.   MSGUSE        = 8;
  159.   MSGCANCEL     = 9;
  160.   MSGOK         = 10;
  161.   MSGCHOOSESM   = 11;
  162.   MSGINFOFMT    = 12;
  163.   MSGH1         = 13;
  164.   MSGH2         = 14;
  165.   MSGH3         = 15;
  166.   MSGH4         = 16;
  167.   MSGH5         = 17;
  168.   MSGH6         = 18;
  169.   MSGH7         = 19;
  170.   MSGH8         = 20;
  171.   MSGH9         = 21;
  172.   MSGH10        = 22;
  173.   MSGH11        = 23;
  174.   MSGH12        = 24;
  175.   MSGH13        = 25;
  176.   MSGH14        = 26;
  177.   MSGH15        = 27;
  178.   MSGH16        = 28;
  179.   MSGH17        = 29;
  180.   MSGH18        = 30;
  181.   MSGH19        = 31;
  182.   MSGH20        = 32;
  183.   MSGH21        = 33;
  184.   MSGH22        = 34;
  185.   MSGH23        = 35;
  186.   MSGH24        = 36;
  187.  
  188.  
  189.   TYPE
  190.     MSGTYPE = ARRAY 37 OF e.LSTRPTR;
  191.  
  192.   CONST
  193.  
  194.     MSGS = MSGTYPE(
  195.       SYS.ADR( "Out of memory"      ),
  196.       SYS.ADR( "Can't open screen"  ),
  197.       SYS.ADR( "Can't open window"  ),
  198.       SYS.ADR( "Can't open file"    ),
  199.       SYS.ADR( "Read/Write Error"   ),
  200.       SYS.ADR( "Retry|Abort"        ),
  201.       SYS.ADR( "File empty"         ),
  202.       SYS.ADR( "Save"               ),
  203.       SYS.ADR( "Use"                ),
  204.       SYS.ADR( "Cancel"             ),
  205.       SYS.ADR( " OK "               ),
  206.       SYS.ADR( "Choose Screen Mode:"),
  207.       SYS.ADR( " File: %-30.30s %ld%% (%ld of %ld Bytes) %ld Lines"),
  208.       SYS.ADR( "\x13                \x15  MuchMore %s Commands:  "),
  209.       SYS.ADR( " \x0dSpace\x05,\x0d LMB\x05:         Start / Stop scrolling, Quit at end of file"),
  210.       SYS.ADR( " \x0dBackSpace\x05,\x0d RMB\x05:     Start / Stop scrolling backwards"),
  211.       SYS.ADR( " \x0dUp\x05/\x0dDown\x05:            Move one line \x0dup\x05 or \x0ddown\x05"),
  212.       SYS.ADR( " \x0dShift \x05+\x0d Up\x05/\x0dDn\x05:      Start / Stop quick scrolling \x0dup\x05 or \x0ddown\x05"),
  213.       SYS.ADR( " \x0dControl\x05:            Increase scroll speed"),
  214.       SYS.ADR( " \x0dAlt\x05+\x0dUp\x05/\x0dDn\x05,\x0d PgUp\x05/\x0dDn\x05: Move one page \x0dup\x05 or \x0ddown\x05"),
  215.       SYS.ADR( " \x0dT\x05,\x0d Home \x05/\x0d B\x05,\x0d End\x05:   Goto \x0dt\x05op / \x0db\x05ottom of text"),
  216.       SYS.ADR( " (\x0DShift\x05) \x0DF\x05, \x0DN\x05, \x0DP\x05:    \x0DF\x05ind string (case sensitive), \x0DN\x05ext, \x0DP\x05revious"),
  217.       SYS.ADR( " \x0dShift \x05+\x0d Fn\x05:         Set textmarker #n to current position"),
  218.       SYS.ADR( " \x0dFn\x05:                 Goto marker #n or set marker #n if it wasn't set yet"),
  219.       SYS.ADR( " \x0dG\x05:                  \x0dG\x05oto line..."),
  220.       SYS.ADR( " \x0dNK 0\x05:               Display info line"),
  221.       SYS.ADR( " \x0dShift \x05+\x0d Alt \x05+\x0d O\x05:    Print text"),
  222.       SYS.ADR( " \x0dW\x05:                  \x0dW\x05rite block between marker #1 and #2 to file or prt"),
  223.       SYS.ADR( " \x0dL\x05:                  \x0dL\x05oad new text"),
  224.       SYS.ADR( " \x0dHELP\x05,\x0d H\x05:            Show commands"),
  225.       SYS.ADR( " \x0dESC\x05,\x0d Q\x05,\x0d X\x05,\x0d NK 5\x05:\x0d    Q\x05uit"),
  226.       SYS.ADR( "© \x131988-94 Fridtjof Siebert & Christian Stiens"),
  227.       SYS.ADR( ""),
  228.       SYS.ADR( "  \x13Please refer to MuchMore.doc for a detailed copyright notice"),
  229.       SYS.ADR( "  This is another product of the Amiga MODULA & OBERON Klub Stuttgart - \x0d\x13AMOK"),
  230.       SYS.ADR( " \x0dC\x05:                  \x0dC\x05opy block between marker #1 and #2 to clipboard"),
  231.       SYS.ADR( " \x0dShift \x05+\x0d Alt \x05+\x0d E\x05:    \x0dE\x05dit text") );
  232.  
  233.  
  234.  
  235. TYPE BusyPointer = ARRAY 36 OF INTEGER;
  236.  
  237. CONST TheBusyPointer = BusyPointer(
  238.   00000U,00000U,
  239.   00400U,007C0U, 00000U,007C0U, 00100U,00380U, 00000U,007E0U,
  240.   007C0U,01FF8U, 01FF0U,03FECU, 03FF8U,07FDEU, 03FF8U,07FBEU,
  241.   07FFCU,0FF7FU, 07EFCU,0FFFFU, 07FFCU,0FFFFU, 03FF8U,07FFEU,
  242.   03FF8U,07FFEU, 01FF0U,03FFCU, 007C0U,01FF8U, 00000U,007E0U,
  243.   00000U,00000U);
  244.  
  245.  
  246. CONST (* RawKey Codes: *)
  247.  
  248.   ESC   = 45H; HELP  = 5FH;
  249.   UP    = 4CH; DOWN  = 4DH;
  250.   SPACE = 40H; BS    = 41H;
  251.   CR    = 44H; ENTER = 43H;
  252.   NK0   = 0FH; NK1   = 1DH; NK2   = 1EH; NK3   = 1FH;
  253.   NK5   = 2EH; NK7   = 3DH; NK8   = 3EH; NK9   = 3FH;
  254.   F1    = 50H; F10   = 59H;
  255.  
  256.  
  257. CONST
  258.   ShowStackSize = 4096;
  259.   BufferSize = 2048;
  260.  
  261.   w = TRUE;
  262.   f = FALSE;
  263.  
  264.   MyIdcmp = LONGSET{I.rawKey,I.mouseButtons,I.closeWindow,I.activeWindow,I.inactiveWindow,I.newSize};
  265.  
  266. (* Control codes: *)
  267.   plain    = 11X;
  268.   italic   = 12X;
  269.   bold     = 13X;
  270.   boldit   = 14X;
  271.   ulineon  = 15X;
  272.   ulineoff = 16X;
  273.  
  274.   Italic = 0;
  275.   Bold   = 1;
  276.   Ulin   = 2;
  277.   Inv    = 3;
  278.  
  279. TYPE
  280.   String    = e.STRING;
  281.   StringPtr = e.STRPTR;
  282.   CharPtr   = UNTRACED POINTER TO CHAR;
  283.   LongPtr   = UNTRACED POINTER TO LONGINT;
  284.  
  285.   TextLinePtr = UNTRACED POINTER TO TextLine;
  286.   TextLine = STRUCT
  287.                prev : TextLinePtr;
  288.                next : TextLinePtr;
  289.                len  : INTEGER;
  290.                size : INTEGER;
  291.                text : String;
  292.              END;
  293.  
  294. CONST
  295.   MaxLen = SIZE(String);
  296.  
  297. TYPE
  298.  
  299.   WBStartupPtr = UNTRACED POINTER TO STRUCT (message : e.Message)
  300.                    process    : d.ProcessId;
  301.                    segment    : e.BPTR;
  302.                    numArgs    : LONGINT;
  303.                    toolWindow : StringPtr;
  304.                    argList : UNTRACED POINTER TO ARRAY 256 OF STRUCT
  305.                                  lock : d.FileLockPtr;
  306.                                  name : StringPtr;
  307.                              END;
  308.                  END;
  309.  
  310.   DiskObjectPtr = UNTRACED POINTER TO STRUCT
  311.                     magic      : INTEGER;
  312.                     version    : INTEGER;
  313.                     gadget     : I.Gadget;
  314.                     type       : SHORTINT;
  315.                     defaultTool: StringPtr;
  316.                     toolTypes  : e.APTR;
  317.                     currentX   : LONGINT;
  318.                     currentY   : LONGINT;
  319.                     drawerData : e.APTR;
  320.                     toolWindow : StringPtr;
  321.                     stackSize  : LONGINT;
  322.                   END;
  323.  
  324.   Args = STRUCT (dummy: d.ArgsStruct)
  325.            b     : LongPtr;
  326.            c     : StringPtr;
  327.            d     : StringPtr;
  328.            e     : StringPtr;
  329.            f     : StringPtr;
  330.            i     : StringPtr;
  331.            o     : StringPtr;
  332.            p     : LongPtr;
  333.            q     : StringPtr;
  334.            s     : LongPtr;
  335.            t     : LongPtr;
  336.            u     : StringPtr;
  337.            x     : LongPtr;
  338.            w     : StringPtr;
  339.            wl    : LongPtr;
  340.            wt    : LongPtr;
  341.            ww    : LongPtr;
  342.            wh    : LongPtr;
  343.            fw    : LongPtr;
  344.            fh    : LongPtr;
  345.            file  : StringPtr;
  346.          END;
  347.  
  348. (*------  Memory:  ------*)
  349.  
  350. CONST ChunkSize = 16384;          (* size of allocated chunks *)
  351.  
  352. TYPE
  353.   MemChunkPtr = UNTRACED POINTER TO MemChunk;  (* chunklist *)
  354.  
  355.   MemChunk = STRUCT
  356.                prev: MemChunkPtr;     (* link *)
  357.                data: ARRAY ChunkSize OF CHAR; (* ChunkSize Bytes of memory *)
  358.              END;
  359.  
  360.  
  361. (*------  Globals  ------*)
  362.  
  363. VAR
  364.   pub            : I.ScreenPtr;        (* default public screen             *)
  365.   Screen         : I.ScreenPtr;        (* MuchMore's Screen                 *)
  366.   Window         : I.WindowPtr;        (* MuchMore's Window                 *)
  367.   rp             : g.RastPortPtr;      (* Screen's RastPort                 *)
  368.   BM             : g.BitMapPtr;        (* Screen's BitMap                   *)
  369.   id             : LONGINT;            (* Display ID                        *)
  370.   catalog        : loc.CatalogPtr;     (* The Catalog                       *)
  371.   MyFile         : d.FileHandlePtr;    (* For loading Textfile              *)
  372.   MyAttr         : g.TextAttr;         (* The selected Font attributes      *)
  373.   MyFont         : g.TextFontPtr;      (* The selected Font                 *)
  374.   FontName       : String;             (* My Font Name or                   *)
  375.   FontSize       : INTEGER;            (* My Font Size                      *)
  376.   FirstLine      : TextLinePtr;        (* the topmost Line                  *)
  377.   TopLine        : TextLinePtr;        (* the topmost Line                  *)
  378.   BottomLine     : TextLinePtr;        (* Last Line displayed on Screen     *)
  379.   LoadLine       : TextLinePtr;        (* currently loaded Line             *)
  380.   LastLine       : TextLinePtr;        (* Last element of LineList          *)
  381.   writeText      : TextLine;           (* temp. Text Line                   *)
  382.   Name,OldName   : String;             (* Text's Name                       *)
  383.   option         : String;             (* CLI Option                        *)
  384.   pubscreenname  : String;
  385.   zoomBox        : ARRAY 4 OF INTEGER;
  386.   editcmd        : String;
  387.   Pens           : String;             (* Screen colors                     *)
  388.   Cols           : ARRAY 4 OF INTEGER; (* Color array for LoadRGB4          *)
  389.   busyPointer    : UNTRACED POINTER TO BusyPointer;
  390.   icon           : DiskObjectPtr;      (* info                              *)
  391.   nameptr        : StringPtr;          (* String Pointer                    *)
  392.   chptr          : CharPtr;            (* Char Pointer                      *)
  393.   PStr           : String;             (* The command for Dos.Execute       *)
  394.   Buffer         : UNTRACED POINTER TO ARRAY BufferSize OF CHAR; (* ReadBuf *)
  395.   RQPos          : LONGINT;            (* Position within ReadBuffer        *)
  396.   RQLen          : LONGINT;            (* Number of CHARs in Buffer         *)
  397.   AnzLines       : LONGINT;            (* Length of Text in Lines           *)
  398.   NumLines       : INTEGER;            (* Number of Lines on Screen         *)
  399.   fontWidth,fontHeight: INTEGER;       (* Font size                         *)
  400.   fontBaseLine   : INTEGER;            (* Font base line                    *)
  401.   spacing        : INTEGER;            (* Extra Line Spacing                *)
  402.   NumColumns     : INTEGER;            (* Number of Columns on Screen       *)
  403.   PageHeight     : INTEGER;            (* fontHeight*NumLines               *)
  404.   i,j            : INTEGER;            (* count                             *)
  405.   left,top       : INTEGER;            (* Dimensions of MMs window          *)
  406.   width,height   : INTEGER;
  407.   initialheight  : INTEGER;
  408.   depth          : INTEGER;            (* Number of planes                  *)
  409.   ci             : INTEGER;            (* Color index                       *)
  410.   scrollmode     : INTEGER;            (* The scrollmode                    *)
  411.   taskpri,oldpri : SHORTINT;           (* Muchmore's Task Priority          *)
  412.   frwidth,frheight:INTEGER;
  413.   MyLock,OldDir  : d.FileLockPtr;      (* To Examine and Load File          *)
  414.   oldcd          : d.FileLockPtr;      (* To save old CD                    *)
  415.   progdir        : d.FileLockPtr;      (* Lock on PROGDIR:                  *)
  416.   clock          : d.FileLockPtr;      (* Lock on C:                        *)
  417.   FileInfo       : d.FileInfoBlockPtr; (* to get File's length              *)
  418.   FileLength,TextLength : LONGINT;     (* Length of File and Displayed Text *)
  419.   ReadLength     : LONGINT;            (* Length of Text while reading      *)
  420.   ScreenPos      : INTEGER;            (* actual position within bitmap     *)
  421.   ShowTask       : e.TaskPtr;          (* the task that displays the text   *)
  422.   ShowStack      : e.APTR;             (* it's stack                        *)
  423.   ShowTaskRunning: BOOLEAN;            (* is Showtask activated?            *)
  424.   win            : BOOLEAN;            (* Is MM running in a window?        *)
  425.   interleaved    : BOOLEAN;            (* Use interleaved Screen?           *)
  426.   zoomed         : BOOLEAN;            (* Is MM iconified ?                 *)
  427.   stdin          : BOOLEAN;            (* Are we reading from STDIN ?       *)
  428.   SignalNewData  : BOOLEAN;            (* Signal when new data is loaded    *)
  429.   SignalAllRead  : BOOLEAN;            (* send signal at end of text        *)
  430.   Done           : BOOLEAN;            (* Quit                              *)
  431.   print          : BOOLEAN;            (* print text?                       *)
  432.   save           : BOOLEAN;            (* save block?                       *)
  433.   copy           : BOOLEAN;            (* copy block to clipboard?          *)
  434.   NewText        : BOOLEAN;            (* load new text                     *)
  435.   Info           : BOOLEAN;            (* is info currently displayed ?     *)
  436.   modeReq        : BOOLEAN;            (* Show Display Mode Requester?      *)
  437.   Scroll         : BOOLEAN;            (* scrolling or waiting?             *)
  438.   Fast           : BOOLEAN;            (* scroll quick?                     *)
  439.   Sync           : BOOLEAN;            (* scroll very quick?                *)
  440.   Decrunched     : BOOLEAN;            (* Is file decrunched?               *)
  441.   Scrollable     : BOOLEAN;            (* is screen able to scroll?         *)
  442.   refresh        : BOOLEAN;            (* Refresh Window?                   *)
  443.   oldstyle       : BOOLEAN;            (* Page Up/Down with soft scroll?    *)
  444.   lace           : BOOLEAN;            (* Is screen interlaced?             *)
  445.   cLocked        : BOOLEAN;            (* Is C: locked ?                    *)
  446.   NewDisp        : BOOLEAN;            (* need to rebuild Display ?         *)
  447.   fastquit       : BOOLEAN;
  448.   ok             : BOOLEAN;
  449.   style          : SHORTSET;           (* Text style                        *)
  450.   mySig          : LONGSET;            (* My Signal Set                     *)
  451.   showSig        : LONGSET;            (* ShowTask's Signal Set             *)
  452.   Me             : d.ProcessPtr;       (* my main task                      *)
  453.   meInt          : LONGINT;            (* for making unique filename        *)
  454.   MyMsgPtr       : I.IntuiMessagePtr;  (* for receiving Messages            *)
  455.   in,out         : d.FileHandlePtr;    (* i/o for TYPE xxx TO PRT:          *)
  456.   mySigBit       : INTEGER;            (* My Signal Bit                     *)
  457.   showSigBit     : INTEGER;            (* ShowTask's Sig Bit                *)
  458.   frame          : INTEGER;            (* Frame Count                       *)
  459.   fg,bg          : INTEGER;            (* Text colors                       *)
  460.   oldfg,oldbg    : INTEGER;            (* Old Text colors                   *)
  461.   tabw           : INTEGER;            (* Tabulator width                   *)
  462.   rd             : d.RDArgsPtr;        (* For ReadArgs                      *)
  463.   args           : Args;               (* My CLI Args                       *)
  464.   ArgPtr         : StringPtr;          (* to get WBArg                      *)
  465.   wbm            : WBStartupPtr;       (* WBenchMessage                     *)
  466.   ri             : g.RasInfoPtr;       (* Screen's ViewPort's RasInfo       *)
  467.   dims           : g.DimensionInfo;    (* Dims for KS2.0                    *)
  468.   disp           : g.DisplayInfo;      (* DisplayInfo for KS2.0             *)
  469.   StrGadget      : I.Gadget;           (* Gadget for Find-Command           *)
  470.   StrInfo        : I.StringInfo;       (* its special info                  *)
  471.   StrExt         : I.StringExtend;     (* its extension                     *)
  472.   asl            : e.LibraryPtr;       (* ASL-librarybase                   *)
  473.   diskFontBase   : e.LibraryPtr;       (* DiskFont-LibraryBase              *)
  474.   xpk            : e.LibraryPtr;       (* XpkMaster-Librarybase             *)
  475.   iconBase       : e.LibraryPtr;       (* Icon-Librarybase                  *)
  476.   Filename       : String;             (* The Filename (without path)       *)
  477.   Dirname        : String;             (* its path                          *)
  478.   Pattern        : ARRAY 80 OF CHAR;   (* The pattern for Filerequester     *)
  479.   TextMarkers    : ARRAY 10 OF TextLinePtr; (* Marked Positions in text     *)
  480.   FindLine       : TextLinePtr;        (* Last found line                   *)
  481.   KeyMap         : ARRAY 50H OF CHAR;  (* console's KeyMap                  *)
  482.   Password       : String;             (* Password for encrypted texts      *)
  483.   conreq         : e.IOStdReqPtr;      (* Console IO-Request                *)
  484.   console        : e.DevicePtr;        (* the console.device                *)
  485.   ievent         : ie.InputEventPtr;   (* InputEvent to convert keycodes    *)
  486.   WriteName      : String;             (* File to write Block               *)
  487.   savefrom,savesize: LONGINT;          (* How much to save?                 *)
  488.   iff            : ip.IFFHandlePtr;    (* IFF Handle for clipboard copy     *)
  489.   buffer         : UNTRACED POINTER TO CHAR; (* Save buffer                 *)
  490.   MemIndex       : INTEGER;            (* index in current Chunk            *)
  491.   CurChunk       : MemChunkPtr;        (* current chunk                     *)
  492.   c              : CHAR;               (* \ used by GetTextLine();          *)
  493.   le             : INTEGER;            (* / global for speed                *)
  494.  
  495.  
  496. (*-------------------------------------------------------------------------*)
  497.  
  498. PROCEDURE OpenDiskFont*{diskFontBase,-30}(VAR textAttr{8}: g.TextAttr): g.TextFontPtr;
  499.  
  500. PROCEDURE GetDiskObject {iconBase,- 78}(name{8}        : ARRAY OF CHAR): DiskObjectPtr;
  501. PROCEDURE FreeDiskObject{iconBase,- 90}(diskobj{8}     : DiskObjectPtr);
  502. PROCEDURE FindToolType  {iconBase,- 96}(toolTypes{8}   : e.APTR;
  503.                                         typeName{9}    : ARRAY OF CHAR): StringPtr;
  504. PROCEDURE MatchToolValue{iconBase,-102}(typeString{8}  : ARRAY OF CHAR;
  505.                                         val{9}         : ARRAY OF CHAR): BOOLEAN;
  506.  
  507. (*-------------------------  ASL Stuff:  ----------------------------------*)
  508.  
  509. CONST
  510.   aslTag  = u.user + 80000H;
  511.  
  512.   taghail   = aslTag + 1;
  513.   window    = aslTag + 2;
  514.   leftEdge  = aslTag + 3;
  515.   topEdge   = aslTag + 4;
  516.   tagWidth  = aslTag + 5;
  517.   tagHeight = aslTag + 6;
  518.   hookFunc  = aslTag + 7;
  519.   file      = aslTag + 8;
  520.   dir       = aslTag + 9;
  521.   pattern   = aslTag + 10;
  522.   funcFlags = aslTag + 20;
  523.   screen    = aslTag + 40;
  524.   sleepWindow=aslTag + 43;
  525.   fiDir     = u.user + 50;
  526.   patGad    = 0;
  527.   fileRequest        = 0;
  528.   screenModeRequest  = 2;
  529.   smPropertyFlags = aslTag+114;
  530.   smPropertyMask  = aslTag+115;
  531.   titleText       = aslTag+1;
  532.   initialDisplayID= aslTag+100;
  533.  
  534. TYPE
  535.   ASLRequesterPtr = UNTRACED POINTER TO ASLRequester;
  536.   ScreenModeRequesterPtr = UNTRACED POINTER TO ScreenModeRequester;
  537.   FileRequesterPtr = UNTRACED POINTER TO FileRequester;
  538.  
  539.   ASLRequester = STRUCT END;
  540.  
  541.   FileRequester = STRUCT (dummy: ASLRequester)
  542.     reserved0 : ARRAY 4 OF e.UBYTE;
  543.     file      : e.STRPTR;
  544.     dir       : e.STRPTR;
  545.     reserved1 : ARRAY 10 OF e.UBYTE;
  546.     leftEdge  : INTEGER;
  547.     topEdge   : INTEGER;
  548.     width     : INTEGER;
  549.     height    : INTEGER;
  550.     reserved2 : ARRAY 2 OF e.UBYTE;
  551.     numArgs   : LONGINT;
  552.     argList   : e.APTR;
  553.     userData  : e.APTR;
  554.     reserved3 : ARRAY 8 OF e.UBYTE;
  555.     pat       : e.STRPTR;
  556.   END;
  557.  
  558.   ScreenModeRequester = STRUCT (dummy: ASLRequester)
  559.     displayID      : LONGINT;
  560.     displayWidth   : LONGINT;
  561.     displayHeight  : LONGINT;
  562.     displayDepth   : INTEGER;
  563.     overscanType   : INTEGER;
  564.     autoScroll     : BOOLEAN;
  565.     pad1           : SHORTINT;
  566.     bitMapWidth    : LONGINT;
  567.     bitMapHeight   : LONGINT;
  568.     leftEdge       : INTEGER;
  569.     topEdge        : INTEGER;
  570.     width          : INTEGER;
  571.     height         : INTEGER;
  572.     infoOpened     : BOOLEAN;
  573.     pad2           : SHORTINT;
  574.     infoLeftEdge   : INTEGER;
  575.     infoTopEdge    : INTEGER;
  576.     infoWidth      : INTEGER;
  577.     infoHeight     : INTEGER;
  578.     userData       : e.APTR;
  579.   END;
  580.  
  581.  
  582. PROCEDURE AllocAslRequestTags{asl,- 48}(reqType{0}: LONGINT; tag1{8}.. : u.Tag): ASLRequesterPtr;
  583. PROCEDURE FreeAslRequest     {asl,- 54}(requester{8}: ASLRequesterPtr);
  584. PROCEDURE AslRequestTags     {asl,- 60}(requester{8}: ASLRequesterPtr; tag1{9}.. : u.Tag): BOOLEAN;
  585.  
  586.  
  587. (*-------------------------------------------------------------------------*)
  588.  
  589. (* $Debug- *)
  590.  
  591. PROCEDURE StuffChar; (* $EntryExitCode- *)
  592. BEGIN
  593.   SYS.INLINE(016C0U, 04E75U)
  594. END StuffChar;
  595.  
  596.  
  597. (*-------------------------------------------------------------------------*)
  598.  
  599.  
  600. PROCEDURE LocStr (num: LONGINT): e.LSTRPTR;
  601. VAR default: e.LSTRPTR;
  602.  
  603. BEGIN
  604.   default := MSGS[num];
  605.   IF loc.base=NIL THEN RETURN default
  606.                   ELSE RETURN loc.GetCatalogStr(catalog,num,default^) END;
  607. END LocStr;
  608.  
  609.  
  610. (*-----------------------------  Requester:  ------------------------------*)
  611.  
  612.  
  613. PROCEDURE Error(Text: ARRAY OF CHAR); (* $CopyArrays- *)
  614. VAR es: I.EasyStruct;
  615.  
  616. BEGIN
  617.   IF ol.wbStarted THEN
  618.     es.structSize   := SIZE(I.EasyStruct);
  619.     es.flags        := LONGSET{};
  620.     es.title        := SYS.ADR(MuchText);
  621.     es.textFormat   := SYS.ADR(Text);
  622.     es.gadgetFormat := LocStr(MSGOK);
  623.     IF I.EasyRequest(NIL,SYS.ADR(es),NIL,NIL)=0 THEN END;
  624.   ELSE
  625.     SYS.SETREG(0,d.Write(d.Output(),Text,str.Length(Text)));
  626.     SYS.SETREG(0,d.Write(d.Output(),"\n",1));
  627.   END;
  628.   HALT(d.fail);
  629. END Error;
  630.  
  631.  
  632. PROCEDURE OutOfMemHandler;
  633. VAR es: I.EasyStruct;
  634.  
  635. BEGIN
  636.   es.structSize   := SIZE(I.EasyStruct);
  637.   es.flags        := LONGSET{};
  638.   es.title        := SYS.ADR(MuchText);
  639.   es.textFormat   := LocStr(MSGOOM);
  640.   es.gadgetFormat := LocStr(MSGRETRYABORT);
  641.   IF I.EasyRequest(NIL,SYS.ADR(es),NIL,NIL)=0 THEN
  642.     HALT(d.fail)
  643.   END;
  644. END OutOfMemHandler;
  645.  
  646.  
  647. (*-------------------------------------------------------------------------*)
  648.  
  649.  
  650. PROCEDURE AllocLine(sz: INTEGER): TextLinePtr;
  651.  
  652. VAR newchunk: MemChunkPtr;
  653.  
  654. BEGIN
  655.   INC(sz,SIZE(TextLine)-MaxLen); IF ODD(sz) THEN INC(sz) END;
  656.   IF MemIndex+sz<=ChunkSize THEN     (* does mem fit into current chunk ? *)
  657.     INC(MemIndex,sz);                (* increment index in current chunk  *)
  658.   ELSE
  659.     NEW(newchunk);                   (* allocate new chunk                *)
  660.     newchunk.prev := CurChunk;       (* link chunk into list              *)
  661.     CurChunk := newchunk;
  662.     MemIndex := sz;
  663.   END;
  664.   RETURN SYS.ADR(CurChunk.data[MemIndex-sz]);
  665. END AllocLine;
  666.  
  667.  
  668. PROCEDURE DisposeLines();
  669.  
  670. VAR chunk: MemChunkPtr;
  671.  
  672. BEGIN
  673.   WHILE CurChunk#NIL DO
  674.     chunk := CurChunk.prev;
  675.     DISPOSE(CurChunk);
  676.     CurChunk := chunk;
  677.   END;
  678.   MemIndex := ChunkSize;
  679. END DisposeLines;
  680.  
  681.  
  682. (*-------------------------------------------------------------------------*)
  683.  
  684.  
  685. PROCEDURE Busy;
  686. BEGIN
  687.   IF Window # NIL THEN
  688.     I.OldModifyIDCMP(Window,MyIdcmp-LONGSET{I.rawKey,I.mouseButtons});
  689.     IF I.base.libNode.version >= 39 THEN
  690.       I.SetWindowPointer(Window,I.waBusyPointer,I.LTRUE,u.done);
  691.     ELSE
  692.       I.SetPointer(Window,busyPointer^,16,16,-6,0);
  693.     END;
  694.   END;
  695. END Busy;
  696.  
  697.  
  698. PROCEDURE UnBusy;
  699. BEGIN
  700.   IF Window # NIL THEN
  701.     IF I.base.libNode.version >= 39 THEN
  702.       I.SetWindowPointer(Window,u.done);
  703.     ELSE
  704.       I.ClearPointer(Window);
  705.     END;
  706.     I.OldModifyIDCMP(Window,MyIdcmp);
  707.   END;
  708. END UnBusy;
  709.  
  710.  
  711. (*------  Scroll:  ------*)
  712.  
  713. PROCEDURE MakeScroll(sync,fast,always: BOOLEAN);
  714. VAR m: INTEGER;
  715.  
  716. BEGIN
  717.   IF Scrollable THEN
  718.     m := 1;
  719.     IF ~always THEN
  720.       IF lace & ~fast THEN m := 2 END;
  721.       IF ~sync THEN INC(m,m*2) END;
  722.     END;
  723.     IF (m=1) OR (frame MOD m=0) THEN
  724.  
  725.       CASE scrollmode OF
  726.  
  727.       | 1: g.ScrollVPort(SYS.ADR(Screen.viewPort));
  728.            g.WaitTOF;
  729.  
  730.       | 2: I.OldMakeScreen(Screen);
  731.            I.OldRethinkDisplay();
  732.  
  733.       (* 3: ScrollRaster *)
  734.  
  735.       | 4: g.WaitTOF;
  736.            g.ScrollVPort(SYS.ADR(Screen.viewPort));
  737.  
  738.       | 5: g.ScrollVPort(SYS.ADR(Screen.viewPort));
  739.            g.WaitBOVP(SYS.ADR(Screen.viewPort));
  740.  
  741.       ELSE (* 0: *)
  742.            I.OldMakeScreen(Screen);
  743.            e.Forbid; SYS.SETREG(0,g.MrgCop(I.ViewAddress())); e.Permit;
  744.            g.WaitTOF;
  745.  
  746.       END;
  747.     END;
  748.     (* $OvflChk- *)
  749.     INC(frame);
  750.     (* $OvflChk= *)
  751.   END;
  752. END MakeScroll;
  753.  
  754.  
  755. (*------  Clear Display:  ------*)
  756.  
  757. PROCEDURE ClearDisplay;
  758. BEGIN
  759.   IF win THEN
  760.     g.SetAPen(rp,0);
  761.     g.RectFill(rp,left,top,left+width-1,top+height-1);
  762.   ELSE
  763.     g.SetRast(rp,0);
  764.   END;
  765.   IF Scrollable THEN
  766.     ri.ryOffset := 0;
  767.     ScreenPos := 0;
  768.     MakeScroll(f,f,w);
  769.   END;
  770. END ClearDisplay;
  771.  
  772. (*-------------------------------------------------------------------------*)
  773.  
  774. (*------  Read one TextLine into a Variable:  ------*)
  775.  
  776.  
  777. PROCEDURE GetTextLine(): TextLinePtr;
  778. (* returns NIL at EOF *)
  779.  
  780. VAR
  781.   l        : TextLinePtr;
  782.   sz,wd,i,j: INTEGER;
  783.   txt      : ARRAY MaxLen+1 OF CHAR;
  784.   num      : ARRAY 10 OF INTEGER;
  785.   newcol   : BOOLEAN;
  786.   oldstyle : SHORTSET;
  787.  
  788.   PROCEDURE GetCh();
  789.   BEGIN
  790.     IF RQPos=RQLen THEN
  791.       RQLen := d.Read(MyFile,Buffer^,BufferSize);
  792.       IF RQLen<0 THEN Error(LocStr(MSGRWERR)^) END;
  793.       RQPos := 0;
  794.     END;
  795.     IF RQLen=0 THEN c := 0X ELSE
  796.       c := Buffer[RQPos]; IF c=0X THEN c:=1X END;
  797.       INC(RQPos); INC(le);
  798.     END;
  799.   END GetCh;
  800.  
  801. BEGIN
  802.   IF RQLen=0 THEN RETURN NIL END;
  803.   sz := 0; wd := 0; le := 0;
  804.   IF Italic IN style THEN IF Bold IN style THEN txt[sz] := boldit ELSE txt[sz] := italic END; INC(sz)
  805.                      ELSE IF Bold IN style THEN txt[sz] := bold; INC(sz) END                      END;
  806.   IF   Ulin IN style     THEN txt[sz] := ulineon; INC(sz) END;
  807.   IF    Inv IN style     THEN txt[sz] := CHR(fg+4*bg+1); INC(sz)
  808.   ELSIF (fg#1) OR (bg#0) THEN txt[sz] := CHR(bg+4*fg+1); INC(sz) END;
  809.   LOOP
  810.     LOOP
  811.       GetCh;
  812.       IF SYS.VAL(CHAR,SYS.VAL(SHORTSET,c)*SHORTSET{0..6})#1BX THEN EXIT END;
  813.       i := -1;
  814.       REPEAT
  815.         GetCh;
  816.         IF (c>=30X) & (c<=39X) THEN
  817.           INC(i); num[i] := 0;
  818.           REPEAT
  819.             num[i] := 10*num[i]+ORD(c)-ORD(30X); GetCh;
  820.           UNTIL (c<30X) OR (c>39X);
  821.         END;
  822.         c := CAP(c);
  823.       UNTIL (c>=3FX(*"?"*)) & (c<=5AX) OR (c=0X) OR (i=9);
  824.       IF c=4DX THEN
  825.         newcol := f; oldstyle := style; j := 0;
  826.         IF i=-1 THEN i:=0; num[0] := 0 END;
  827.         WHILE (i>=j) & (sz<MaxLen-1) DO
  828.           CASE num[j] OF
  829.           0:  style := SHORTSET{}; fg := 1; bg := 0; newcol := w |
  830.           1:  INCL(style,Bold) |
  831.           2:  fg := 2; newcol := w |
  832.           3:  INCL(style,Italic) |
  833.           4:  INCL(style,Ulin) |
  834.           7:  INCL(style,Inv); newcol := w |
  835.           8:  oldfg:=fg; oldbg:=bg; fg:=0; bg:=0; newcol := w |
  836.  
  837.           22: EXCL(style,Bold); fg := 1; newcol := w |
  838.           23: EXCL(style,Italic) |
  839.           24: EXCL(style,Ulin) |
  840.           27: EXCL(style,Inv); newcol := w |
  841.           28: fg:=oldfg; bg:=oldbg; newcol := w |
  842.  
  843.           30..37: fg := (num[j]-30) MOD 4; newcol := w |
  844.           39:     fg := 1; newcol := w |
  845.  
  846.           40..47: bg := (num[j]-40) MOD 4; newcol := w |
  847.           49:     bg := 0; newcol := w |
  848.  
  849.           ELSE END;
  850.           INC(j);
  851.         END;
  852.         IF (oldstyle#style) & (sz<MaxLen) THEN
  853.           IF Italic IN style THEN IF Bold IN style THEN txt[sz] := boldit ELSE txt[sz] := italic END;
  854.                              ELSE IF Bold IN style THEN txt[sz] := bold   ELSE txt[sz] := plain  END;
  855.           END;
  856.           INC(sz);
  857.           IF (Ulin IN style) THEN
  858.             IF ~((Ulin IN oldstyle)) & (sz<MaxLen) THEN
  859.               txt[sz] := ulineon;
  860.               INC(sz);
  861.             END;
  862.           ELSE
  863.             IF (Ulin IN oldstyle) & (sz<MaxLen) THEN
  864.               txt[sz] := ulineoff;
  865.               INC(sz);
  866.             END;
  867.           END;
  868.         END;
  869.         IF newcol & (sz<MaxLen) THEN
  870.           IF Inv IN style THEN txt[sz] := CHR(fg+4*bg+1)
  871.                           ELSE txt[sz] := CHR(bg+4*fg+1) END;
  872.           INC(sz);
  873.         END;
  874.       END;   (* IF c="m" THEN *)
  875.     END;   (* LOOP *)
  876.     CASE c OF
  877.       020X.. 7FX:   txt[sz] := c; INC(sz); INC(wd) |
  878.       0A1X..0FFX:   txt[sz] := c; INC(sz); INC(wd) |
  879.       8X: (* BS *)  IF wd>0 THEN DEC(sz); DEC(wd); END |
  880.       9X: (* TAB *) REPEAT
  881.                       txt[sz] := 20X; INC(sz); INC(wd)
  882.                     UNTIL (sz=MaxLen) OR (wd=NumColumns) OR (sz MOD tabw=0) |
  883.       0A0X:         txt[sz] := 20X; INC(sz); INC(wd) |
  884.       0AX,0X,0CX:   EXIT
  885.     ELSE
  886.     END;
  887.     IF (wd>=NumColumns) OR (sz>=MaxLen) THEN EXIT END;
  888.   END;
  889.   txt[sz] := 0X; INC(sz);
  890.   l := AllocLine(sz);
  891.   l.len := le; l.size:= sz;
  892.   WHILE sz>0 DO DEC(sz); l.text[sz] := txt[sz] END;
  893.   INC(ReadLength,le);
  894.   RETURN l;
  895. END GetTextLine;
  896.  
  897.  
  898. (*------  Write Line to Screen:  ------*)
  899.  
  900.  
  901. PROCEDURE Type(pos: INTEGER; line: TextLinePtr);
  902.  
  903. VAR
  904.   style: SHORTSET;
  905.   front,back: SHORTINT;
  906.   c: CHAR;
  907.   last,i,x,y: INTEGER;
  908.   strPtr: StringPtr;
  909.  
  910. BEGIN
  911.   g.SetDrMd(rp,g.jam2);
  912.   IF Scrollable THEN
  913.     g.SetAPen(rp,0);
  914.     y := pos * fontHeight;
  915.     IF ~refresh THEN g.RectFill(rp,0,y,width-1,y+fontHeight-spacing-1) END;
  916.   END;
  917.   i := 0; x := 0; style := SHORTSET{}; front := 1; back := 0;
  918.   LOOP
  919.     WHILE line.text[i] < " " DO
  920.       c := line.text[i];
  921.       IF c=0X THEN EXIT END;
  922.       CASE c OF
  923.       plain   : style := style - SHORTSET{g.bold,g.italic} |
  924.       italic  : EXCL(style,g.bold); INCL(style,g.italic)   |
  925.       bold    : INCL(style,g.bold); EXCL(style,g.italic)   |
  926.       boldit  : style := style + SHORTSET{g.bold,g.italic} |
  927.       ulineon : INCL(style,g.underlined) |
  928.       ulineoff: EXCL(style,g.underlined) |
  929.       1X..10X : DEC(c);
  930.                 front := SHORT(ORD(c)) DIV 4;
  931.                 back  := SHORT(ORD(c)) MOD 4 |
  932.       ELSE END;
  933.       INC(i);
  934.     END;
  935.     strPtr := SYS.ADR(line.text[i]); last := i;
  936.     REPEAT INC(i) UNTIL line.text[i]<" ";
  937.     SYS.SETREG(0,g.SetSoftStyle(rp,style,-SHORTSET{}));
  938.     g.SetAPen(rp,front);
  939.     g.SetBPen(rp,back);
  940.     g.Move(rp,left+fontWidth*x,top+fontHeight*pos+fontBaseLine);
  941.     g.Text(rp,strPtr^,i-last);
  942.     INC(x,i-last);
  943.   END;
  944. END Type;
  945.  
  946.  
  947. PROCEDURE CopyScrollLine(pos: INTEGER);
  948. (* Kopiert die an pos geschriebene Zeile auf den entsprechenden
  949.  * DoubleBuffer-Bereich
  950.  * ACHTUNG: Darf nur aufgerufen werden, wenn Scrollable TRUE ist!
  951.  *)
  952.  
  953. VAR
  954.   y,z: INTEGER;
  955.  
  956. BEGIN
  957.   y := pos*fontHeight;
  958.   z := PageHeight;
  959.   IF pos >= NumLines THEN z := -z END;
  960.   SYS.SETREG(0,g.BltBitMap(BM, 0,y, BM, 0,y+z, width,fontHeight, 0C0X, SHORTSET{0..7}, NIL));
  961. END CopyScrollLine;
  962.  
  963.  
  964. (*------  Copy String to TextLine:  ------*)
  965.  
  966.  
  967. PROCEDURE CopyToWriteText(String: StringPtr);
  968. VAR i,j : INTEGER;
  969.  
  970. BEGIN
  971.   e.CopyMem(String^,writeText.text,MaxLen-1);
  972.   j := 0;
  973.   FOR i := 0 TO SHORT(str.Length(writeText.text))-1 DO
  974.     IF writeText.text[i] >= " " THEN INC(j) END;
  975.     IF j >= NumColumns THEN
  976.       writeText.text[i] := 0X;
  977.       RETURN
  978.     END;
  979.   END;
  980. END CopyToWriteText;
  981.  
  982.  
  983. (*------  Write String to Screen (at any position):  ------*)
  984.  
  985.  
  986. PROCEDURE TypeTo(VAR text: TextLine; pos: INTEGER);
  987.  
  988. BEGIN
  989.   IF pos < NumLines THEN
  990.     IF Scrollable THEN
  991.       INC(pos,ScreenPos);
  992.       Type(pos,SYS.ADR(text));
  993.       CopyScrollLine(pos);
  994.     ELSE
  995.       Type(pos,SYS.ADR(text));
  996.     END;
  997.   END;
  998. END TypeTo;
  999.  
  1000.  
  1001. (*------  Write String to Screen (at any position):  ------*)
  1002.  
  1003.  
  1004. PROCEDURE WriteTo(String: StringPtr; pos: INTEGER);
  1005.  
  1006. BEGIN
  1007.   CopyToWriteText(String);
  1008.   TypeTo(writeText,pos);
  1009. END WriteTo;
  1010.  
  1011.  
  1012. (*------  Write Line at Bottom of Text:  ------*)
  1013.  
  1014.  
  1015. PROCEDURE AddBottomLine(Line: TextLinePtr; Fast: BOOLEAN);
  1016. VAR i,y: INTEGER;
  1017.  
  1018. BEGIN
  1019.   IF ~Scrollable THEN
  1020.     g.SetAPen(rp,0); g.SetBPen(rp,0);
  1021.     IF Fast THEN
  1022.       g.ScrollRaster(rp,0,fontHeight,left,top,left+width-1,top+height-1);
  1023.       IF Sync THEN g.WaitTOF END;
  1024.     ELSE
  1025.       i := fontHeight;
  1026.       REPEAT
  1027.         IF Window.height=initialheight THEN (* Prevent crash under v37 *)
  1028.           g.ScrollRaster(rp,0,1,left,top,left+width-1,top+height-1);
  1029.         END;
  1030.         IF Sync THEN g.WaitTOF END;
  1031.         DEC(i);
  1032.       UNTIL i=0;
  1033.     END;
  1034.     Type(NumLines-1,Line);
  1035.   ELSE
  1036.     Type(ScreenPos+NumLines,Line);
  1037.     y := ScreenPos*fontHeight;
  1038.     IF Fast THEN
  1039.       INC(ri.ryOffset,fontHeight);
  1040.       MakeScroll(Sync,w,f);
  1041.       SYS.SETREG(0,g.BltBitMap(BM, 0,y+PageHeight, BM, 0,y, width,fontHeight, 0C0X, SHORTSET{0..7}, NIL));
  1042.     ELSE
  1043.       i := fontHeight;
  1044.       REPEAT
  1045.         INC(ri.ryOffset);
  1046.         MakeScroll(Sync,f,f);
  1047.         SYS.SETREG(0,g.BltBitMap(BM, 0,y+PageHeight, BM, 0,y, width,1, 0C0X, SHORTSET{0..7}, NIL));
  1048.         INC(y);
  1049.         DEC(i);
  1050.       UNTIL i=0;
  1051.     END;
  1052.     INC(ScreenPos);
  1053.     IF ScreenPos=NumLines THEN
  1054.       ScreenPos := 0;
  1055.       ri.ryOffset := 0;
  1056.     END;
  1057.   END;
  1058. END AddBottomLine;
  1059.  
  1060.  
  1061. (*------  Check whether BottomLine.next is NIL or not:  ------*)
  1062.  
  1063.  
  1064. PROCEDURE TryBottomnext(): BOOLEAN;
  1065. (* returns TRUE if BottomLine.next#NIL END; *)
  1066.  
  1067. BEGIN
  1068.   IF (BottomLine.next=NIL) & (MyFile#NIL) THEN
  1069.     SignalNewData := w;
  1070.     SYS.SETREG(0,e.Wait(showSig));
  1071.     SignalNewData := f;
  1072.   END;
  1073.   RETURN BottomLine.next#NIL;
  1074. END TryBottomnext;
  1075.  
  1076.  
  1077. (*------  Scroll down one Line:  ------*)
  1078.  
  1079.  
  1080. PROCEDURE ScrollDown(Fast: BOOLEAN);
  1081.  
  1082. BEGIN
  1083.   IF TryBottomnext() THEN
  1084.     BottomLine := BottomLine.next;
  1085.     INC(AnzLines);
  1086.     INC(TextLength,BottomLine.len);
  1087.   ELSE RETURN END;
  1088.   IF AnzLines >= NumLines THEN TopLine := TopLine.next END;
  1089.   AddBottomLine(BottomLine,Fast);
  1090. END ScrollDown;
  1091.  
  1092.  
  1093. (*------  Scroll Up one Line:  ------*)
  1094.  
  1095.  
  1096. PROCEDURE ScrUp (Fast: BOOLEAN);
  1097. VAR
  1098.   i,y: INTEGER;
  1099.  
  1100. BEGIN
  1101.   IF ~Scrollable THEN
  1102.     g.SetAPen(rp,0); g.SetBPen(rp,0);
  1103.     IF Fast THEN
  1104.       g.ScrollRaster(rp,0,-fontHeight,left,top,left+width-1,top+height-1);
  1105.       IF Sync THEN g.WaitTOF END;
  1106.     ELSE
  1107.       i := fontHeight;
  1108.       REPEAT
  1109.         IF Window.height=initialheight THEN
  1110.           g.ScrollRaster(rp,0,-1,left,top,left+width-1,top+height-1);
  1111.         END;
  1112.         IF Sync THEN g.WaitTOF END;
  1113.         DEC(i)
  1114.       UNTIL i=0;
  1115.     END;
  1116.     IF TopLine.prev#NIL THEN Type(0,TopLine.prev) ELSE Type(0,FirstLine) END;
  1117.   ELSE
  1118.     IF ScreenPos=0 THEN
  1119.       ri.ryOffset := NumLines*fontHeight;
  1120.       ScreenPos := NumLines;
  1121.     END;
  1122.     DEC(ScreenPos);
  1123.     IF TopLine.prev#NIL THEN Type(ScreenPos,TopLine.prev) ELSE Type(ScreenPos,FirstLine) END;
  1124.     y := ScreenPos*fontHeight;
  1125.     IF Fast THEN
  1126.       DEC(ri.ryOffset,fontHeight);
  1127.       MakeScroll(Sync,w,f);
  1128.       SYS.SETREG(0,g.BltBitMap(BM, 0,y, BM, 0,y+PageHeight, width,fontHeight , 0C0X, SHORTSET{0..7}, NIL));
  1129.     ELSE
  1130.       INC(y,fontHeight);
  1131.       i := fontHeight;
  1132.       REPEAT
  1133.         DEC(ri.ryOffset);
  1134.         MakeScroll(Sync,f,f);
  1135.         DEC(y);
  1136.         SYS.SETREG(0,g.BltBitMap(BM, 0,y, BM, 0,y+PageHeight, width,1, 0C0X, SHORTSET{0..7}, NIL));
  1137.         DEC(i);
  1138.       UNTIL i=0;
  1139.     END;
  1140.   END;
  1141. END ScrUp;
  1142.  
  1143.  
  1144. PROCEDURE ScrollUp(Fast: BOOLEAN);
  1145.  
  1146. BEGIN
  1147.   IF (TopLine.prev#NIL) & (TopLine.prev.prev#NIL) THEN
  1148.     TopLine := TopLine.prev;
  1149.     DEC(TextLength,BottomLine.len);
  1150.     DEC(AnzLines);
  1151.     BottomLine := BottomLine.prev;
  1152.     ScrUp(Fast);
  1153.   END;
  1154. END ScrollUp;
  1155.  
  1156.  
  1157. (*------  Undo last AddBottomLine:  ------*)
  1158.  
  1159.  
  1160. PROCEDURE DelLine(Fast: BOOLEAN);
  1161.  
  1162. BEGIN
  1163.   ScrUp(Fast);
  1164.   Info := f;
  1165. END DelLine;
  1166.  
  1167.  
  1168. (*------  Convert String to Integer:  ------*)
  1169.  
  1170. PROCEDURE StrToInt(str: StringPtr; base: INTEGER): LONGINT;
  1171.  
  1172. VAR
  1173.   i,j: INTEGER;
  1174.   num: LONGINT;
  1175.   ch : CHAR;
  1176.   neg: BOOLEAN;
  1177.  
  1178. BEGIN
  1179.   num := 0; i := 0; neg := f;
  1180.   IF  str^[0] = '-'                   THEN str:=SYS.ADR(str[1]); neg := w END;
  1181.   IF  str^[0] = '$'                   THEN str:=SYS.ADR(str[1]); base:=16 END;
  1182.   IF (str^[0]='0')&(CAP(str^[1])='X') THEN str:=SYS.ADR(str[2]); base:=16 END;
  1183.   LOOP
  1184.     IF i=LEN(str^) THEN EXIT END;
  1185.     ch := CAP(str^[i]);
  1186.     IF ch=0X THEN EXIT END;
  1187.     j := ORD(ch);
  1188.     CASE ch OF
  1189.       "0".."9": DEC(j,ORD('0'))   |
  1190.       "A".."F": DEC(j,ORD('A')-10);
  1191.                 IF base=10 THEN base:=16; i:=-1; j:=0; num:=0 END;
  1192.       ELSE EXIT
  1193.     END;
  1194.     num := num * base + j;
  1195.     INC(i);
  1196.   END;
  1197.   IF neg THEN num := -num END;
  1198.   RETURN num
  1199. END StrToInt;
  1200.  
  1201.  
  1202. (*-------------------------------------------------------------------------*)
  1203.  
  1204.  
  1205. PROCEDURE GetLength(t: TextLinePtr);
  1206.  
  1207. BEGIN
  1208.   TextLength := 0; AnzLines := 0;
  1209.   WHILE t#NIL DO INC(AnzLines); INC(TextLength,t.len); t := t.prev END;
  1210. END GetLength;
  1211.  
  1212.  
  1213. (*-------------------------------------------------------------------------*)
  1214.  
  1215.  
  1216. PROCEDURE NewDisplay;
  1217. (* Zeichnet ab BottomLine neu *)
  1218.  
  1219. VAR
  1220.   i: INTEGER;
  1221.   l: TextLinePtr;
  1222.  
  1223. BEGIN
  1224.   IF ~refresh THEN ClearDisplay END;
  1225.   l := BottomLine.prev;
  1226.   IF l#NIL THEN BottomLine := l END;
  1227.   l := BottomLine;
  1228.   i := NumLines-1;
  1229.   WHILE (i>0) & TryBottomnext() DO
  1230.     BottomLine := BottomLine.next;
  1231.     DEC(i);
  1232.   END;
  1233.   WHILE (i>0) & (l.prev#NIL) DO
  1234.     l := l.prev;
  1235.     DEC(i);
  1236.   END;
  1237.   TopLine := l.next;
  1238.   WHILE i<NumLines DO
  1239.     BottomLine := l;
  1240.     TypeTo(BottomLine^,i);
  1241.     INC(i);
  1242.     l := l.next;
  1243.   END;
  1244.   GetLength(BottomLine);
  1245.   Scroll := f;
  1246.   Info := f;
  1247. END NewDisplay;
  1248.  
  1249.  
  1250. (*-------------------------------------------------------------------------*)
  1251.  
  1252.  
  1253. PROCEDURE GetString(VAR str: ARRAY OF CHAR; int,newdisp,hide: BOOLEAN);
  1254. VAR
  1255.   Win: I.WindowPtr;
  1256.   msg: I.IntuiMessagePtr;
  1257.   class: LONGSET;
  1258.   l,t,w,h: INTEGER;
  1259.   screen: I.ScreenPtr;
  1260.  
  1261. BEGIN
  1262.   MakeScroll(f,f,TRUE);
  1263.   Busy;
  1264.   screen := Screen;
  1265.   w := width DIV 4 * 3;
  1266.   l := (width-w) DIV 2;
  1267.   t := height DIV 2;
  1268.   IF Screen # NIL THEN
  1269.     IF Scrollable THEN INC(t,ri.ryOffset) END;
  1270.     h := Screen.font.ySize+4;
  1271.   ELSE
  1272.     screen := Window.wScreen;
  1273.     INC(l,Window.leftEdge);
  1274.     INC(t,Window.topEdge);
  1275.     h := screen.font.ySize+4;
  1276.   END;
  1277.   StrGadget.leftEdge   := 4;
  1278.   StrGadget.topEdge    := 2;
  1279.   StrGadget.width      := w-8;
  1280.   StrGadget.height     := h-4;
  1281.   StrGadget.activation := {I.stringCenter,I.relVerify};
  1282.   IF int THEN INCL(StrGadget.activation,I.longint) END;
  1283.   StrGadget.flags      := {};
  1284.   StrGadget.gadgetType := I.strGadget;
  1285.   StrGadget.specialInfo:= SYS.ADR(StrInfo);
  1286.   StrInfo.buffer       := SYS.ADR(str);
  1287.   StrInfo.maxChars     := SHORT(LEN(str))-1;
  1288.   StrInfo.extension    := SYS.ADR(StrExt);
  1289.   IF hide THEN INCL(StrGadget.flags,I.stringExtend) END;
  1290.  
  1291.   IF Scrollable THEN Screen.height := Screen.height * 2 END;
  1292.  
  1293.   Win := I.OpenWindowTagsA(NIL,
  1294.                            I.waLeft,  l,
  1295.                            I.waTop,   t,
  1296.                            I.waWidth, w,
  1297.                            I.waHeight,h,
  1298.                            I.waIDCMP, LONGSET{I.gadgetUp,I.activeWindow,I.inactiveWindow},
  1299.                            I.waFlags, LONGSET{I.rmbTrap,I.activate,I.noCareRefresh},
  1300.                            I.waGadgets,SYS.ADR(StrGadget),
  1301.                            I.waCustomScreen,screen,
  1302.                            u.done);
  1303.  
  1304.   IF Scrollable THEN Screen.height := Screen.height DIV 2 END;
  1305.  
  1306.   IF Win # NIL THEN
  1307.     e.WaitPort(Win.userPort);
  1308.     SYS.SETREG(0,I.ActivateGadget(StrGadget,Win,NIL));
  1309.     LOOP
  1310.       e.WaitPort(Win.userPort);
  1311.       msg := e.GetMsg(Win.userPort);
  1312.       IF msg # NIL THEN
  1313.         class := msg.class;
  1314.         e.ReplyMsg(msg);
  1315.         IF (I.gadgetUp IN class) OR (I.inactiveWindow IN class) THEN
  1316.           EXIT
  1317.         END;
  1318.       END;
  1319.     END;
  1320.     I.CloseWindow(Win); Win := NIL;
  1321.   END;
  1322.   UnBusy;
  1323.   IF newdisp & ~win THEN
  1324.     refresh := TRUE; BottomLine := TopLine; NewDisplay; refresh := f;
  1325.   END;
  1326. END GetString;
  1327.  
  1328.  
  1329. (*-------------------------------------------------------------------------*)
  1330.  
  1331.  
  1332. PROCEDURE * ShowProc;
  1333.  
  1334. VAR
  1335.   l           : TextLinePtr;
  1336.   Down        : BOOLEAN;          (* Scroll-Direction                  *)
  1337.   Shift       : BOOLEAN;          (* Shifted Keystroke ?               *)
  1338.   Alt         : BOOLEAN;          (* Altered Keystroke ?               *)
  1339.   wasInfo     : BOOLEAN;          (* was Info line displayed ?         *)
  1340.   found       : BOOLEAN;          (* TRUE, if find was successful      *)
  1341.   chr         : CHAR;             (* converted keycode                 *)
  1342.   caseDelta   : SHORTINT;         (* Case sensitive Search?            *)
  1343.   flen        : INTEGER;          (* length of findstring              *)
  1344.   i,j         : INTEGER;          (* Count                             *)
  1345.   Class       : LONGSET;          (* contains Message.class            *)
  1346.   Code        : INTEGER;          (* contains Message.code             *)
  1347.   Qualifier   : SET;              (* contains Message.qualifier        *)
  1348.   Find,FindStr: ARRAY 80 OF CHAR; (* findstring / capital findstring   *)
  1349.   Goto        : ARRAY 10 OF CHAR; (* string containing goto line #     *)
  1350.   li          : LONGINT;          (* longint value of line to go to    *)
  1351.   HiText      : TextLine;         (* Highlited textline                *)
  1352.   OldHiText   : TextLinePtr;      (* original, un-hilited text         *)
  1353.   skipTab     : ARRAY 256 OF INTEGER;(* for Boyer-Moore Alg.           *)
  1354.  
  1355.  
  1356.   PROCEDURE WaitAllRead();
  1357.  
  1358.   BEGIN
  1359.     IF MyFile # NIL THEN
  1360.       Busy;
  1361.       SignalAllRead := w;
  1362.       SYS.SETREG(0,e.Wait(showSig));
  1363.       SignalAllRead := f;
  1364.       UnBusy;
  1365.     END;
  1366.   END WaitAllRead;
  1367.  
  1368.  
  1369.   PROCEDURE HiLite(at,len: INTEGER);
  1370.   (* Hilites len chars of BottomLine.text starting at position at *)
  1371.  
  1372.   VAR
  1373.     c: INTEGER;
  1374.     col: CHAR;
  1375.  
  1376.   BEGIN
  1377.     OldHiText := BottomLine; HiText := OldHiText^; BottomLine := SYS.ADR(HiText);
  1378.     IF at+len+2<MaxLen THEN
  1379.       c := 0; col := 5X;
  1380.       WHILE c<at DO
  1381.         IF HiText.text[c]<CHR(17) THEN col := HiText.text[c] END;
  1382.         INC(c);
  1383.       END;
  1384.       HiText.text[at] := CHR(17-ORD(col));
  1385.       c := at; INC(len,at);
  1386.       WHILE c<len DO
  1387.         HiText.text[c+1] := OldHiText.text[c];
  1388.         INC(c);
  1389.       END;
  1390.       HiText.text[c+1] := col;
  1391.       REPEAT
  1392.         HiText.text[c+2] := OldHiText.text[c];
  1393.         INC(c);
  1394.       UNTIL HiText.text[c-1]=0X;
  1395.     END;
  1396.     IF HiText.next#NIL THEN HiText.next.prev := SYS.ADR(HiText) END;
  1397.     IF HiText.prev#NIL THEN HiText.prev.next := SYS.ADR(HiText) END;
  1398.   END HiLite;
  1399.  
  1400.  
  1401.   PROCEDURE UnHiLite();
  1402.  
  1403.   BEGIN
  1404.     IF HiText.next#NIL THEN HiText.next.prev := OldHiText END;
  1405.     IF HiText.prev#NIL THEN HiText.prev.next := OldHiText END;
  1406.   END UnHiLite;
  1407.  
  1408.  
  1409.   PROCEDURE CalcSkipTab;  (* Make skip-table for Boyer-Moore Alg. *)
  1410.   VAR i,j: INTEGER;
  1411.  
  1412.   BEGIN
  1413.     FOR i := 0 TO 255 DO skipTab[i] := flen END;
  1414.     i := 0;
  1415.     FOR j := flen-1 TO 0 BY -1 DO
  1416.       IF skipTab[ORD(FindStr[j])] = flen THEN
  1417.         skipTab[ORD(FindStr[j])] := i;
  1418.       END;
  1419.       INC(i);
  1420.     END;
  1421.   END CalcSkipTab;
  1422.  
  1423.  
  1424.   PROCEDURE Search(): BOOLEAN;
  1425.   (* Searches string and hilites it if found. Result is TRUE if string found *)
  1426.  
  1427.   VAR ch: CHAR;
  1428.       i,j,t: INTEGER;
  1429.  
  1430.   BEGIN
  1431.     IF flen > BottomLine.size THEN RETURN f END;
  1432.     i := flen-1;
  1433.     FOR j := flen-1 TO 0 BY -1 DO
  1434.       LOOP
  1435.         ch := BottomLine.text[i];
  1436.         CASE ch OF "a".."z","à".."ö","ø".."þ": DEC(ch,caseDelta) ELSE END;
  1437.         IF ch = FindStr[j] THEN EXIT END;
  1438.         t := skipTab[ORD(ch)];
  1439.         IF flen-j > t THEN INC(i,flen-j) ELSE INC(i,t) END;
  1440.         IF i >= BottomLine.size THEN RETURN f END;
  1441.         j := flen-1;
  1442.       END;
  1443.       DEC(i);
  1444.     END;
  1445.     INC(i); IF i<0 THEN RETURN f END;
  1446.     SYS.SETREG(0,TryBottomnext());
  1447.     FindLine := BottomLine;
  1448.     HiLite(i,flen);
  1449.     found := w; RETURN w;
  1450.   END Search;
  1451.  
  1452.  
  1453.   PROCEDURE ShowInfo(Fast: BOOLEAN);
  1454.   VAR IStr : String;
  1455.       fmt  : e.LSTRPTR;
  1456.       i    : INTEGER;
  1457.       data : STRUCT name : e.STRPTR;
  1458.                     perc : LONGINT;
  1459.                     tlen : LONGINT;
  1460.                     flen : LONGINT;
  1461.                     lins : LONGINT;
  1462.              END;
  1463.   BEGIN
  1464.     data.name := SYS.ADR(OldName);
  1465.     data.tlen := TextLength;
  1466.     data.flen := FileLength;
  1467.     IF data.flen=0 THEN data.flen := ReadLength END;
  1468.     IF data.flen=0 THEN data.flen := 1 END;
  1469.     data.perc := TextLength * 100 DIV data.flen;
  1470.     data.lins := AnzLines-1;
  1471.     fmt := LocStr(MSGINFOFMT);
  1472.     e.OldRawDoFmt(fmt^,SYS.ADR(data),StuffChar,SYS.ADR(IStr));
  1473.     IStr[0] := 7X; IF depth<2 THEN IStr[0] := 2X END;
  1474.     i := SHORT(str.Length(IStr));
  1475.     REPEAT IStr[i] := 20X; INC(i) UNTIL (i>=LEN(IStr)-2) OR (i>=NumColumns+2);
  1476.     IStr[i] := 0X;
  1477.     CopyToWriteText(SYS.ADR(IStr));
  1478.     AddBottomLine(SYS.ADR(writeText),Fast);
  1479.     Info := w;
  1480.     Scroll := f;
  1481.   END ShowInfo;
  1482.  
  1483.  
  1484.   PROCEDURE Help; (* executed when HELP or H is pressed *)
  1485.  
  1486.   CONST
  1487.     num = 25;
  1488.  
  1489.   VAR
  1490.     i,j  : INTEGER;
  1491.     help : ARRAY num OF e.LSTRPTR;
  1492.     fmt  : e.LSTRPTR;
  1493.     data : StringPtr;
  1494.     h1   : String;
  1495.  
  1496.   BEGIN
  1497.     data := SYS.ADR(Version);
  1498.     fmt := LocStr(MSGH1);
  1499.     e.OldRawDoFmt(fmt^,SYS.ADR(data),StuffChar,SYS.ADR(h1));
  1500.     help[ 0] := SYS.ADR(h1);
  1501.     help[ 1] := SYS.ADR("");
  1502.     help[ 2] := LocStr(MSGH2);
  1503.     help[ 3] := LocStr(MSGH3);
  1504.     help[ 4] := LocStr(MSGH4);
  1505.     help[ 5] := LocStr(MSGH5);
  1506.     help[ 6] := LocStr(MSGH6);
  1507.     help[ 7] := LocStr(MSGH7);
  1508.     help[ 8] := LocStr(MSGH8);
  1509.     help[ 9] := LocStr(MSGH9);
  1510.     help[10] := LocStr(MSGH10);
  1511.     help[11] := LocStr(MSGH11);
  1512.     help[12] := LocStr(MSGH12);
  1513.     help[13] := LocStr(MSGH13);
  1514.     help[14] := LocStr(MSGH24);
  1515.     help[15] := LocStr(MSGH14);
  1516.     help[16] := LocStr(MSGH23);
  1517.     help[17] := LocStr(MSGH15);
  1518.     help[18] := LocStr(MSGH16);
  1519.     help[19] := LocStr(MSGH17);
  1520.     help[20] := LocStr(MSGH18);
  1521.     help[21] := SYS.ADR("");
  1522.     help[22] := LocStr(MSGH19);
  1523.     help[23] := LocStr(MSGH21);
  1524.     help[24] := LocStr(MSGH22);
  1525.     ClearDisplay();
  1526.     j := (NumLines - num) DIV 2; IF j<0 THEN j:=0 END;
  1527.     i := 0;
  1528.     WHILE (i<num) & (i+j<NumLines) DO
  1529.       WriteTo(SYS.VAL(StringPtr,help[i]),j+i);
  1530.       INC(i);
  1531.     END;
  1532.     LOOP
  1533.       e.WaitPort(Window.userPort);
  1534.       MyMsgPtr := e.GetMsg(Window.userPort);
  1535.       IF (LONGSET{I.rawKey,I.mouseButtons}*MyMsgPtr.class#LONGSET{}) & (MyMsgPtr.code<128) THEN EXIT END;
  1536.       e.ReplyMsg(MyMsgPtr);
  1537.     END;
  1538.     e.ReplyMsg(MyMsgPtr);
  1539.     BottomLine := TopLine;
  1540.     NewDisplay
  1541.   END Help;
  1542.  
  1543.  
  1544.   PROCEDURE Bottom;  (* executed when END or B is pressed *)
  1545.  
  1546.   BEGIN
  1547.     WaitAllRead;
  1548.     BottomLine := LastLine;
  1549.     NewDisplay
  1550.   END Bottom;
  1551.  
  1552.  
  1553.   PROCEDURE Space(): BOOLEAN;  (* executed if space or LMB is pressed *)
  1554.   (* IF result=w THEN EXIT END *)
  1555.  
  1556.   BEGIN
  1557.     IF (MyFile=NIL) & (BottomLine.next=NIL) THEN        (* End of file? *)
  1558.       IF wasInfo THEN RETURN w END;
  1559.       ShowInfo(Shift);
  1560.     ELSE
  1561.       IF Down THEN
  1562.         Scroll := ~Scroll;
  1563.         IF ~Scroll THEN ShowInfo(Fast) END;
  1564.       ELSE
  1565.         Down := w;
  1566.         Scroll := w;
  1567.       END;
  1568.       Fast := Shift;
  1569.     END;
  1570.     RETURN f;
  1571.   END Space;
  1572.  
  1573.  
  1574.   PROCEDURE BackSpace;  (* executed if backspace or RMB is pressed *)
  1575.  
  1576.   BEGIN
  1577.     Fast := Shift;
  1578.     Scroll := Down OR ~Scroll;
  1579.     Down := f
  1580.   END BackSpace;
  1581.  
  1582.  
  1583. BEGIN
  1584.   (* $IF SmallData *)
  1585.   SYS.SETREG(13,e.AbsExecBase.thisTask.userData);
  1586.   (* $END *)
  1587.  
  1588.   (* $IFNOT ClearVars *)
  1589.   Find[0] := 0X; FindStr[0] := 0X; Goto[0] := 0X;
  1590.   (* $END *)
  1591.  
  1592.   Down := w;
  1593.  
  1594.   SYS.SETREG(0,e.AllocSignal(Window.userPort.sigBit));
  1595.   Window.userPort.sigTask := e.FindTask(NIL);
  1596.  
  1597.   showSigBit := e.AllocSignal(-1);
  1598.   showSig    := LONGSET{showSigBit};
  1599.  
  1600.   e.Signal(Me,mySig);
  1601.   SYS.SETREG(0,e.Wait(showSig));
  1602.  
  1603.   LOOP
  1604.  
  1605.     IF NewDisp THEN NewDisp := f; NewDisplay END;
  1606.  
  1607. (*------  Type Text:  ------*)
  1608.  
  1609.     LOOP
  1610.       IF Scroll THEN
  1611.         IF Down THEN
  1612.           ScrollDown(Fast);
  1613.           Scroll := (MyFile#NIL) OR (BottomLine.next#NIL);
  1614.         ELSE
  1615.           ScrollUp(Fast);
  1616.           Scroll := (TopLine.prev#NIL) & (TopLine.prev.prev#NIL);
  1617.         END;
  1618.       ELSE
  1619.         MakeScroll(f,f,w);
  1620.         e.WaitPort(Window.userPort);
  1621.       END;
  1622.  
  1623.       MyMsgPtr := e.GetMsg(Window.userPort);
  1624.  
  1625.       IF MyMsgPtr # NIL THEN
  1626.         IF ~(I.inactiveWindow IN MyMsgPtr.class) THEN EXIT END;
  1627.         e.ReplyMsg(MyMsgPtr);
  1628.         I.OldModifyIDCMP(Window,MyIdcmp-LONGSET{I.mouseButtons});
  1629.         e.WaitPort(Window.userPort);
  1630.         I.OldModifyIDCMP(Window,MyIdcmp);
  1631.       END;
  1632.  
  1633.     END;
  1634.  
  1635.     Code      := MyMsgPtr.code;
  1636.     Class     := MyMsgPtr.class;
  1637.     Qualifier := MyMsgPtr.qualifier;
  1638.  
  1639.     e.ReplyMsg(MyMsgPtr);
  1640.  
  1641.     Shift := {ie.lShift,ie.rShift,ie.capsLock} * Qualifier # {};
  1642.     Alt   := {ie.lAlt  ,ie.rAlt}               * Qualifier # {};
  1643.     Sync  := ~ (ie.control IN Qualifier);
  1644.  
  1645.     IF ~Sync THEN Shift := w END;
  1646.  
  1647.  
  1648.     IF ((I.rawKey       IN Class) & (Code<80H)) OR
  1649.        ((I.mouseButtons IN Class) & ({ie.leftButton,ie.rightButton}*Qualifier#{}))
  1650.     THEN
  1651.       wasInfo := f;
  1652.       IF Info THEN DelLine(Shift); wasInfo := w; END;
  1653.     END;
  1654.  
  1655.  
  1656.     IF I.mouseButtons IN Class THEN
  1657.  
  1658.       IF    (ie.leftButton IN Qualifier)   & Space()   THEN EXIT
  1659.       ELSIF ie.rightButton IN Qualifier THEN BackSpace END;
  1660.  
  1661.     ELSIF I.closeWindow IN Class THEN
  1662.       EXIT;
  1663.  
  1664.     ELSIF (I.newSize IN Class) THEN
  1665.       Scroll := f;
  1666.       zoomed := w;
  1667.       IF Window.height = initialheight THEN
  1668.         zoomed := f;
  1669.         BottomLine := TopLine;
  1670.         NewDisplay;
  1671.       END;
  1672.  
  1673.     ELSIF (I.rawKey IN Class) & (Code<80H) & ~zoomed THEN
  1674.  
  1675.       CASE Code OF
  1676.  
  1677.       | SPACE: IF Space() THEN EXIT END                     (* Space *)
  1678.  
  1679.       | BS:    BackSpace                                    (* BackSpace *)
  1680.  
  1681.       | DOWN,NK2,NK3:                                       (* Down *)
  1682.  
  1683.           IF (MyFile=NIL) & (BottomLine.next=NIL) THEN
  1684.             I.DisplayBeep(NIL)
  1685.           ELSE
  1686.             IF Shift & (Code # NK3) THEN
  1687.               Scroll := ~Down OR ~Scroll OR ~Fast;
  1688.               Fast := w; Down := w;
  1689.             ELSE
  1690.               IF Alt OR (Code=NK3) THEN
  1691.                 IF oldstyle THEN
  1692.                   i := NumLines-1;
  1693.                   REPEAT
  1694.                     ScrollDown(w);
  1695.                     DEC(i);
  1696.                   UNTIL i=0;
  1697.                 ELSE
  1698.                   IF BottomLine.next#NIL THEN BottomLine := BottomLine.next END;
  1699.                   NewDisplay;
  1700.                 END;
  1701.               ELSE
  1702.                 ScrollDown(w);
  1703.               END;
  1704.               Scroll := f;
  1705.             END;
  1706.           END;
  1707.  
  1708.       | UP,NK8,NK9:                                        (* Up *)
  1709.  
  1710.           IF (TopLine.prev=NIL) OR (TopLine.prev.prev=NIL) THEN
  1711.             I.DisplayBeep(NIL)
  1712.           ELSE
  1713.             IF Shift & (Code # NK9) THEN
  1714.               Scroll := Down OR ~Scroll OR ~Fast;
  1715.               Fast := w; Down := f;
  1716.             ELSE
  1717.               IF Alt OR (Code=NK9) THEN
  1718.                 i := NumLines-1;
  1719.                 IF oldstyle THEN
  1720.                   REPEAT
  1721.                     ScrollUp(w);
  1722.                     DEC(i);
  1723.                   UNTIL i=0;
  1724.                 ELSE
  1725.                   (*IF TopLine.prev#NIL THEN*)
  1726.                   BottomLine := TopLine;
  1727.                   WHILE (i>0) & (BottomLine.prev#NIL) DO
  1728.                     BottomLine := BottomLine.prev;
  1729.                     DEC(i);
  1730.                   END;
  1731.                   NewDisplay;
  1732.                   (*END;*)
  1733.                 END;
  1734.               ELSE
  1735.                 ScrollUp(w);
  1736.               END;
  1737.               Scroll := f;
  1738.             END;
  1739.           END;
  1740.  
  1741.       | CR,ENTER: ScrollDown(f); Scroll := f;              (* CR *)
  1742.  
  1743.       | NK7: BottomLine := FirstLine; NewDisplay           (* Home *)
  1744.  
  1745.       | NK1: Bottom                                        (* End *)
  1746.  
  1747.       | F1..F10:                                           (* F1..F10 *)
  1748.  
  1749.           i := Code-F1;
  1750.           IF ~ Shift & (TextMarkers[i]#NIL) THEN
  1751.             BottomLine := TextMarkers[i];
  1752.             NewDisplay;
  1753.           ELSE
  1754.             TextMarkers[i] := TopLine;
  1755.           END
  1756.  
  1757.       | NK0:  IF ~wasInfo THEN ShowInfo(Shift) END;        (* NK 0 *)
  1758.  
  1759.       | HELP: Help                                         (* Help *)
  1760.  
  1761.       | ESC:  EXIT                                         (* Quit *)
  1762.  
  1763.       | NK5:  IF wasInfo OR fastquit THEN EXIT ELSE ShowInfo(Shift)END; (* safe Quit *)
  1764.  
  1765.       ELSE
  1766.  
  1767.         IF Code<40H THEN         (* examine vanilla keycode: *)
  1768.  
  1769.           chr := KeyMap[Code];
  1770.  
  1771.           CASE chr OF
  1772.  
  1773.           | "t": BottomLine := FirstLine; NewDisplay       (* Home *)
  1774.  
  1775.           | "b": Bottom;                                   (* End *)
  1776.  
  1777.           | "f","n","p":                                   (* Find, Next, Previous *)
  1778.  
  1779.             IF chr="f" THEN
  1780.               caseDelta := 32; IF Shift THEN caseDelta := 0 END;
  1781.               GetString(Find,f,w,f);
  1782.               FindLine := NIL; flen := 0;
  1783.               LOOP
  1784.                 FindStr[flen] := Find[flen];
  1785.                 CASE FindStr[flen] OF
  1786.                   "a".."z","à".."ö","ø".."þ": DEC(FindStr[flen],caseDelta) |
  1787.                   0X: EXIT;
  1788.                 ELSE
  1789.                 END;
  1790.                 INC(flen);
  1791.               END;
  1792.               CalcSkipTab;
  1793.             END;
  1794.             found := f;
  1795.             IF FindStr # "" THEN
  1796.               Busy;
  1797.               i := NumLines;
  1798.               IF FindLine # NIL THEN FindLine := FindLine.next END;
  1799.               WHILE (i>0) & (BottomLine#NIL) & (BottomLine#FindLine) DO
  1800.                 BottomLine := BottomLine.prev; DEC(i);
  1801.               END;
  1802.               IF (BottomLine # FindLine) OR (BottomLine=NIL) THEN
  1803.                 BottomLine := TopLine
  1804.               END;
  1805.               IF chr # "p" THEN                          (* next *)
  1806.                 WHILE (BottomLine # NIL) & ~ Search() DO
  1807.                   SYS.SETREG(0,TryBottomnext());
  1808.                   BottomLine := BottomLine.next;
  1809.                 END;
  1810.               ELSE                                       (* previous *)
  1811.                 IF BottomLine.prev#NIL THEN BottomLine:=BottomLine.prev END;
  1812.                 REPEAT
  1813.                   BottomLine := BottomLine.prev
  1814.                 UNTIL (BottomLine=NIL) OR Search();
  1815.               END;
  1816.               IF BottomLine#NIL THEN
  1817.                 li := NumLines DIV 2;
  1818.                 WHILE (li>0) & (BottomLine.prev#NIL) DO BottomLine := BottomLine.prev; DEC(li) END;
  1819.               END;
  1820.               UnBusy;
  1821.             END;
  1822.  
  1823.             IF ~ found THEN
  1824.               I.DisplayBeep(NIL);
  1825.               BottomLine := TopLine;
  1826.             END;
  1827.             NewDisplay;
  1828.             IF found THEN UnHiLite END;
  1829.  
  1830.           | "w","c":                                       (* write block *)
  1831.             IF (TextMarkers[0]#NIL) & (TextMarkers[1]#NIL) & ~print & ~save THEN
  1832.               savefrom := 0; savesize := 0;
  1833.               l := TextMarkers[0].prev; WHILE l.prev#NIL DO l := l.prev; INC(savefrom,l.len) END;
  1834.               l := TextMarkers[1].prev; WHILE l#NIL DO INC(savesize,l.len); l := l.prev END;
  1835.               l := TextMarkers[1]; i := NumLines; WHILE (i>1) & (l#NIL) DO DEC(i); INC(savesize,LONG(l.len)); l := l.next END;
  1836.               DEC(savesize,savefrom);
  1837.               IF savesize>0 THEN
  1838.                 IF chr="c" THEN copy := w ELSE
  1839.                   GetString(WriteName,f,w,f);
  1840.                   copy := f;
  1841.                 END;
  1842.                 WaitAllRead; save := w; e.Signal(Me,mySig);
  1843.               END
  1844.             END
  1845.  
  1846.           | "o","e":                                       (* Print, Edit *)
  1847.  
  1848.             IF Shift & Alt & ~print & ~save THEN
  1849.               nameptr := SYS.ADR(Name);
  1850.               IF chr="o" THEN
  1851.                 e.OldRawDoFmt('Type "%s" to PRT:',SYS.ADR(nameptr),StuffChar,SYS.ADR(PStr));
  1852.               ELSE
  1853.                 e.OldRawDoFmt(editcmd,SYS.ADR(nameptr),StuffChar,SYS.ADR(PStr));
  1854.               END;
  1855.               WaitAllRead; print := w; e.Signal(Me,mySig);
  1856.             END
  1857.  
  1858.           | "l":                                           (* Load Text *)
  1859.  
  1860.             ClearDisplay;
  1861.             NewText := w; e.Signal(Me,mySig);
  1862.             REPEAT UNTIL (showSigBit IN e.Wait(showSig)) & ~ NewText |
  1863.  
  1864.           | "g":                                           (* goto *)
  1865.  
  1866.             GetString(Goto,w,w,f);
  1867.             li := SHORT(StrInfo.longInt);
  1868.             Busy;
  1869.             BottomLine := FirstLine;
  1870.             WHILE (li >= 0) & TryBottomnext() DO
  1871.               BottomLine := BottomLine.next;
  1872.               DEC(li)
  1873.             END;
  1874.             UnBusy;
  1875.             NewDisplay
  1876.  
  1877.           | "h":     Help                                  (* Help *)
  1878.  
  1879.           | "q","x": IF wasInfo OR fastquit THEN EXIT ELSE ShowInfo(Shift) END; (* safe Quit *)
  1880.  
  1881.           ELSE END;
  1882.  
  1883.         END;   (* IF Code<40H THEN *)
  1884.  
  1885.       END;   (* CASE Code OF *)
  1886.  
  1887.     END;   (* IF I.rawKey IN Class THEN *)
  1888.  
  1889.   END;   (* LOOP *)
  1890.  
  1891.   Done := w;
  1892.   e.Signal(Me,mySig);
  1893.   LOOP SYS.SETREG(0,e.Wait(LONGSET{})) END;
  1894.  
  1895. END ShowProc;
  1896.  
  1897. (* $Debug= *)
  1898.  
  1899.  
  1900. (*--------------------------  File Requester:  ----------------------------*)
  1901.  
  1902.  
  1903. PROCEDURE FileReq(VAR Name: String);
  1904.  
  1905. VAR
  1906.   fr: FileRequesterPtr;
  1907.   pub,scr: I.ScreenPtr;
  1908.   i,j: INTEGER;
  1909.   res: BOOLEAN;
  1910.   screenTag: LONGINT;
  1911.  
  1912. BEGIN
  1913.   j := SHORT(str.Length(Name));
  1914.   WHILE (j>0) & (Name[j]#":") & (Name[j]#"/") DO DEC(j) END;
  1915.   IF j=0 THEN j := -1 END;
  1916.   i := 0;
  1917.   WHILE i<=j DO Dirname[i] := Name[i]; INC(i) END; Dirname[i] := 0X;
  1918.   j := 0;
  1919.   REPEAT Filename[j] := Name[i]; INC(j); INC(i) UNTIL Name[i-1]=0X;
  1920.  
  1921.   IF asl=NIL THEN
  1922.     asl := e.OpenLibrary("asl.library",36);
  1923.     IF asl=NIL THEN Error("Can't open asl.library") END;
  1924.   END;
  1925.  
  1926.   IF (Window # NIL) & (asl.version >= 38) THEN
  1927.     screenTag := screen;
  1928.     scr := Window.wScreen;
  1929.   ELSE
  1930.     screenTag := u.ignore;
  1931.     scr := NIL;
  1932.     pub := I.LockPubScreen(NIL);
  1933.     IF pub # NIL THEN
  1934.       I.ScreenToFront(pub);
  1935.       I.UnlockPubScreen(NIL,pub);
  1936.     END;
  1937.   END;
  1938.  
  1939.   fr := AllocAslRequestTags(fileRequest,
  1940.                             screenTag,scr,
  1941.                             taghail, SYS.ADR(MuchText),
  1942.                             file,    SYS.ADR(Filename),
  1943.                             dir,     SYS.ADR(Dirname),
  1944.                             pattern, SYS.ADR(Pattern),
  1945.                             funcFlags,ASH(1,patGad),
  1946.                             tagWidth, frwidth,
  1947.                             tagHeight,frheight,
  1948.                             u.done);
  1949.   IF fr=NIL THEN Error(LocStr(MSGOOM)^) END;
  1950.  
  1951.   res := AslRequestTags(fr,u.done);
  1952.  
  1953.   IF res THEN
  1954.     COPY(fr.file^,Filename);
  1955.     COPY(fr.dir^,Dirname);
  1956.   END;
  1957.  
  1958.   frwidth  := fr.width;
  1959.   frheight := fr.height;
  1960.   COPY(fr.pat^,Pattern);
  1961.  
  1962.   FreeAslRequest(fr);
  1963.   IF ~res THEN HALT(d.ok) END;
  1964.  
  1965.   Name := Dirname;
  1966.   i := SHORT(str.Length(Name));
  1967.   IF (i>0) THEN
  1968.     CASE Name[i-1] OF "/",":": ELSE
  1969.       Name[i] := "/"; INC(i);
  1970.     END;
  1971.   END;
  1972.   j := 0;
  1973.   LOOP
  1974.     Name[i] := Filename[j];
  1975.     IF (Name[i]=0X) OR (i=255) THEN EXIT END;
  1976.     INC(i);
  1977.     INC(j);
  1978.   END;
  1979.   Name[i] := 0X;
  1980.   IF Window # NIL THEN
  1981.     I.ScreenToFront(Window.wScreen);
  1982.     I.ActivateWindow(Window);
  1983.   END;
  1984. END FileReq;
  1985.  
  1986.  
  1987. (*--------------------------  Decrunch:  ----------------------------*)
  1988.  
  1989.  
  1990. PROCEDURE DirExists(name: ARRAY OF CHAR): BOOLEAN; (* $CopyArrays- *)
  1991. VAR lock: d.FileLockPtr;
  1992.     result: BOOLEAN;
  1993.     oldwp: e.APTR;
  1994. BEGIN
  1995.   result := f;
  1996.   oldwp := Me.windowPtr;
  1997.   Me.windowPtr := -1;
  1998.   lock := d.Lock(name,d.sharedLock);
  1999.   IF lock # NIL THEN
  2000.     result := w;
  2001.     d.UnLock(lock)
  2002.   END;
  2003.   Me.windowPtr := oldwp;
  2004.   RETURN result
  2005. END DirExists;
  2006.  
  2007.  
  2008. PROCEDURE Decrunch;
  2009.  
  2010. CONST
  2011.   tagBase    = u.user + ORD("X")*256 + ORD("P");
  2012.   inName     = tagBase+01H;
  2013.   inFH       = tagBase+02H;
  2014.   outName    = tagBase+10H;
  2015.   password   = tagBase+24H;
  2016.   getError   = tagBase+25H;
  2017.   shortError = tagBase+31H;
  2018.   typePacked = 1;
  2019.   flagsPassword = 0;
  2020.  
  2021. TYPE
  2022.   XpkFib = STRUCT
  2023.     type       : LONGINT;    (* Unpacked, packed, archive? *)
  2024.     uLen       : LONGINT;
  2025.     cLen       : LONGINT;
  2026.     nLen       : LONGINT;
  2027.     uCur       : LONGINT;
  2028.     cCur       : LONGINT;
  2029.     id         : LONGINT;
  2030.     packer     : ARRAY 6 OF CHAR;
  2031.     subVersion : INTEGER;
  2032.     masVersion : INTEGER;
  2033.     flags      : LONGSET;
  2034.     head       : ARRAY 16 OF CHAR;
  2035.     ratio      : LONGINT;
  2036.     reserved   : ARRAY 8 OF LONGINT;
  2037.   END;
  2038.  
  2039. VAR
  2040.   file: d.FileHandlePtr;
  2041.   err: LONGINT;
  2042.   xpkFib: XpkFib;
  2043.   errBuf: ARRAY 81 OF CHAR;
  2044.  
  2045.   PROCEDURE ExamineTags {xpk,-36}(VAR fib{8}  : XpkFib;
  2046.                                   tag1{9}..   : e.APTR): LONGINT;
  2047.   PROCEDURE UnpackTags  {xpk,-48}(tag1{8}..   : e.APTR): LONGINT;
  2048.  
  2049. BEGIN
  2050.   Decrunched := f;
  2051.   OldName := Name;
  2052.   IF stdin THEN RETURN END;
  2053.  
  2054.   IF DirExists("T:") THEN Name := "T:" ELSE Name := "RAM:" END;
  2055.  
  2056.   e.OldRawDoFmt("Decrunched.%lx",SYS.ADR(meInt),StuffChar,SYS.ADR(Name[str.Length(Name)]));
  2057.  
  2058.   IF xpk=NIL THEN xpk := e.OpenLibrary("xpkmaster.library",1) END;
  2059.   IF xpk # NIL THEN
  2060.     err := ExamineTags(xpkFib,inFH,SYS.VAL(LONGINT,MyFile),u.done);
  2061.     IF (err#0) & (err#-20) THEN
  2062.       Error(LocStr(MSGOOM)^)
  2063.     END;
  2064.     IF (err=-20) OR (xpkFib.type#typePacked) THEN
  2065.       Name := OldName;
  2066.       RETURN
  2067.     END;
  2068.     IF flagsPassword IN xpkFib.flags THEN GetString(Password,f,f,w) END;
  2069.     Busy;
  2070.     err := UnpackTags(inFH,       SYS.VAL(LONGINT,MyFile),
  2071.                       outName,    SYS.ADR(Name),
  2072.                       password,   SYS.ADR(Password),
  2073.                       getError,   SYS.ADR(errBuf),
  2074.                       shortError, e.true,
  2075.                       u.done);
  2076.     UnBusy;
  2077.     IF err#0 THEN Error(errBuf) END;
  2078.     file := d.Open(Name,d.oldFile);
  2079.     IF file#NIL THEN
  2080.       Decrunched := w;
  2081.       d.OldClose(MyFile);
  2082.       MyFile := file;
  2083.       RETURN
  2084.     ELSE
  2085.       Error(LocStr(MSGCOF)^);
  2086.     END;
  2087.   END;
  2088.   Name := OldName;
  2089. END Decrunch;
  2090.  
  2091.  
  2092. (*-----------------  Screen Mode Requester:  ------------------------*)
  2093.  
  2094.  
  2095. PROCEDURE ScreenModeReq (VAR displayID : LONGINT): BOOLEAN;
  2096.  
  2097. VAR
  2098.   smReq: ScreenModeRequesterPtr;
  2099.   ok: BOOLEAN;
  2100.   initID: LONGINT;
  2101.  
  2102. BEGIN
  2103.   initID := displayID;
  2104.   IF initID = g.invalidID THEN initID := 0 END;
  2105.  
  2106.   IF asl=NIL THEN
  2107.     asl := e.OpenLibrary("asl.library",36);
  2108.     IF asl=NIL THEN Error("Can't open asl.library") END;
  2109.   END;
  2110.  
  2111.   IF asl.version < 38 THEN Error("asl v38 required") END;
  2112.  
  2113.   smReq := AllocAslRequestTags(screenModeRequest,u.done);
  2114.   IF smReq=NIL THEN RETURN f END;
  2115.  
  2116.   ok := AslRequestTags(smReq,
  2117.                        initialDisplayID , initID,
  2118.                        smPropertyFlags  , LONGSET{g.isWB},
  2119.                        smPropertyMask   , LONGSET{g.isWB},
  2120.                        u.done);
  2121.  
  2122.   IF ok THEN displayID := smReq.displayID END;
  2123.  
  2124.   FreeAslRequest(smReq);
  2125.  
  2126.   RETURN ok;
  2127.  
  2128. END ScreenModeReq;
  2129.  
  2130.  
  2131. (*-------------------------------------------------------------------------*)
  2132.  
  2133.  
  2134. PROCEDURE SavePrefs(save: BOOLEAN);
  2135.  
  2136.   PROCEDURE SavePrefsName(name: StringPtr);
  2137.   VAR file: d.FileHandlePtr;
  2138.       l: LONGINT;
  2139.   BEGIN
  2140.     file := d.Open(name^,d.newFile);
  2141.     IF file # NIL THEN
  2142.       SYS.SETREG(0,d.Write(file,"FORM",4));
  2143.       l := 16;
  2144.       SYS.SETREG(0,d.Write(file,l,4));
  2145.       SYS.SETREG(0,d.Write(file,"MUMO",4));
  2146.       SYS.SETREG(0,d.Write(file,"DPID",4));
  2147.       l := 4;
  2148.       SYS.SETREG(0,d.Write(file,l,4));
  2149.       SYS.SETREG(0,d.Write(file,id,4));
  2150.       d.OldClose(file);
  2151.     END;
  2152.   END SavePrefsName;
  2153.  
  2154. BEGIN
  2155.   SavePrefsName(SYS.ADR("ENV:MuchMore.prefs"));
  2156.   IF save THEN
  2157.     SavePrefsName(SYS.ADR("ENVARC:MuchMore.prefs"))
  2158.   END;
  2159. END SavePrefs;
  2160.  
  2161.  
  2162. (*-------------------------------------------------------------------------*)
  2163.  
  2164.  
  2165. PROCEDURE LoadPrefs;
  2166.  
  2167. VAR file: d.FileHandlePtr;
  2168.     l,i,s: LONGINT;
  2169.     buf: ARRAY 80 OF CHAR;
  2170.     ok: BOOLEAN;
  2171.  
  2172. BEGIN
  2173.   file := NIL;
  2174.   IF DirExists("PROGDIR:") THEN
  2175.     file := d.Open("PROGDIR:MuchMore.prefs",d.oldFile);
  2176.   END;
  2177.   IF (file=NIL) & DirExists("ENV:") THEN
  2178.     file := d.Open("ENV:MuchMore.prefs",d.oldFile);
  2179.   END;
  2180.   IF file # NIL THEN
  2181.     LOOP
  2182.       IF (d.Read(file,i,4) <= 0)        OR
  2183.          (i # SYS.VAL(LONGINT,"FORM"))  OR
  2184.          (d.Read(file,s,4) <= 0)        OR
  2185.          (d.Read(file,i,4) <= 0)        OR
  2186.          (i # SYS.VAL(LONGINT,"MUMO"))    THEN EXIT END;
  2187.       WHILE w DO
  2188.         IF (d.Read(file,i,4) <= 0)      OR
  2189.            (d.Read(file,s,4) <= 0)        THEN EXIT END;
  2190.         IF ODD(s) THEN INC(s) END;
  2191.         IF (s=4) & (i=SYS.VAL(LONGINT,"DPID")) THEN
  2192.           SYS.SETREG(0,d.Read(file,id,4));
  2193.         ELSE
  2194.           IF s < 0 THEN EXIT END;
  2195.           SYS.SETREG(0,d.Seek(file,s,d.current));
  2196.         END;
  2197.       END;
  2198.  
  2199.       EXIT;
  2200.     END;
  2201.     d.OldClose(file);
  2202.   END;
  2203.   IF (d.GetVar("EDITOR",buf,SIZE(buf),LONGSET{})>0) THEN
  2204.     COPY(buf,editcmd);
  2205.   END;
  2206. END LoadPrefs;
  2207.  
  2208.  
  2209. (*------------------------  Get Tooltypes:  --------------------------*)
  2210.  
  2211.  
  2212. PROCEDURE ParseIcon(icon: DiskObjectPtr);
  2213. VAR tt: StringPtr;
  2214.  
  2215. BEGIN
  2216.   IF icon # NIL THEN
  2217.     tt := FindToolType(icon.toolTypes,"PALETTE");    IF (tt # NIL) THEN COPY(tt^,Pens) END;
  2218.     tt := FindToolType(icon.toolTypes,"EXTRASPACE"); IF (tt # NIL) THEN spacing := SHORT(StrToInt(tt,10)) END;
  2219.     tt := FindToolType(icon.toolTypes,"FONT");       IF (tt # NIL) THEN COPY(tt^,FontName) END;
  2220.     tt := FindToolType(icon.toolTypes,"EDITOR");     IF (tt # NIL) THEN COPY(tt^,editcmd) END;
  2221.     tt := FindToolType(icon.toolTypes,"OLDSTYLE");   IF (tt # NIL) THEN oldstyle := ~MatchToolValue(tt^,"FALSE") END;
  2222.     tt := FindToolType(icon.toolTypes,"FASTQUIT");   IF (tt # NIL) THEN fastquit := ~MatchToolValue(tt^,"FALSE") END;
  2223.     tt := FindToolType(icon.toolTypes,"INTERLEAVED");IF (tt # NIL) THEN interleaved := ~MatchToolValue(tt^,"FALSE") END;
  2224.     tt := FindToolType(icon.toolTypes,"PLANES");     IF (tt # NIL) THEN depth := SHORT(StrToInt(tt,10)) END;
  2225.     tt := FindToolType(icon.toolTypes,"TABWIDTH");   IF (tt # NIL) THEN tabw := SHORT(StrToInt(tt,10)) END;
  2226.     tt := FindToolType(icon.toolTypes,"PUBSCREEN");  IF (tt # NIL) THEN COPY(tt^,pubscreenname) END;
  2227.     tt := FindToolType(icon.toolTypes,"TOOLPRI");    IF (tt # NIL) THEN taskpri := SHORT(SHORT(StrToInt(tt,10))) END;
  2228.     tt := FindToolType(icon.toolTypes,"SCROLLMODE"); IF (tt # NIL) THEN scrollmode := SHORT(StrToInt(tt,10)) END;
  2229.     tt := FindToolType(icon.toolTypes,"LEFTEDGE");   IF (tt # NIL) THEN left  := SHORT(StrToInt(tt,10)) END;
  2230.     tt := FindToolType(icon.toolTypes,"TOPEDGE");    IF (tt # NIL) THEN top   := SHORT(StrToInt(tt,10)) END;
  2231.     tt := FindToolType(icon.toolTypes,"WIDTH");      IF (tt # NIL) THEN width := SHORT(StrToInt(tt,10)) END;
  2232.     tt := FindToolType(icon.toolTypes,"HEIGHT");     IF (tt # NIL) THEN height:= SHORT(StrToInt(tt,10)) END;
  2233.     tt := FindToolType(icon.toolTypes,"WINDOW");     IF (tt # NIL) THEN win := (MatchToolValue(tt^,"TRUE")) END;
  2234.     tt := FindToolType(icon.toolTypes,"FRWIDTH");    IF (tt # NIL) THEN frwidth := SHORT(StrToInt(tt,10)) END;
  2235.     tt := FindToolType(icon.toolTypes,"FRHEIGHT");   IF (tt # NIL) THEN frheight := SHORT(StrToInt(tt,10)) END;
  2236.     FreeDiskObject(icon);
  2237.   END;
  2238. END ParseIcon;
  2239.  
  2240.  
  2241. (*------------------------------  MAIN:  ----------------------------------*)
  2242.  
  2243. BEGIN
  2244.  
  2245. (*------  Init:  ------*)
  2246.  
  2247.   mySigBit := -1;
  2248.   Me := SYS.VAL(d.ProcessPtr,ol.Me);
  2249.   meInt := SYS.VAL(LONGINT,Me);
  2250.   OldDir := Me.currentDir;
  2251.   oldpri := Me.task.node.pri; taskpri := oldpri;
  2252.   WriteName := "PRT:";
  2253.   MemIndex := ChunkSize;
  2254.   Sync := w;
  2255.   FontSize := 8;
  2256.   Pattern := "~(#?.(info|backdrop))";
  2257.   editcmd := 'C:Ed';
  2258.   id := g.invalidID;
  2259.   tabw := 8;
  2260.   depth := 2;
  2261.   left   := 0;
  2262.   top    := 0;
  2263.   width  := 640;
  2264.   height := 200;
  2265.   frwidth:= 300;
  2266.   frheight := 200;
  2267.   scrollmode := 1;
  2268.  
  2269.   IF (I.base.libNode.version < 37) OR (g.base.libNode.version < 37) THEN
  2270.     IF I.DisplayAlert(0,"\x00\x64\x14Need OS2 or higher!\o",50) THEN END;
  2271.     HALT(d.fail);
  2272.   END;
  2273.  
  2274.   mySigBit := e.AllocSignal(-1);
  2275.   IF mySigBit<0 THEN HALT(d.fail) END;
  2276.   mySig := LONGSET{mySigBit};
  2277.  
  2278.   iconBase := e.OpenLibrary("icon.library",0);
  2279.  
  2280.   IF loc.base # NIL THEN
  2281.     catalog := loc.OpenCatalog(NIL,"muchmore.catalog",u.end);
  2282.   END;
  2283.  
  2284.   ol.OutOfMemHandler := OutOfMemHandler;
  2285.  
  2286.   INCL(ol.MemReqs,e.public);
  2287.  
  2288.   ol.New(ShowStack,ShowStackSize);
  2289.   NEW(ShowTask);
  2290.   NEW(FileInfo);
  2291.   NEW(ievent);
  2292.   NEW(conreq);
  2293.   NEW(Buffer);
  2294.  
  2295.   INCL(ol.MemReqs,e.chip);
  2296.   NEW(busyPointer);
  2297.   e.CopyMem(TheBusyPointer,busyPointer^,SIZE(busyPointer^));
  2298.   EXCL(ol.MemReqs,e.chip);
  2299.  
  2300. (*------  Setup:  ------*)
  2301.  
  2302.   NEW(FirstLine);
  2303. (*FirstLine.size := 0;
  2304.   FirstLine.text[0] := 0X; *)
  2305.  
  2306. (*------  Start:  ------*)
  2307.  
  2308.   LoadPrefs;
  2309.  
  2310.   IF ol.wbStarted THEN
  2311.  
  2312.     wbm := ol.wbenchMsg;
  2313.     IF iconBase # NIL THEN
  2314.       j := SHORT(wbm.numArgs); IF j>2 THEN j := 2 END;
  2315.       FOR i := 0 TO j-1 DO
  2316.         SYS.SETREG(0,d.CurrentDir(wbm.argList[i].lock));
  2317.         nameptr := wbm.argList[i].name;
  2318.         icon := GetDiskObject(nameptr^);
  2319.         IF icon=NIL THEN
  2320.           IF d.base.lib.version >= 37 THEN
  2321.             SYS.SETREG(0,d.CurrentDir(d.GetProgramDir()));
  2322.             icon := GetDiskObject(nameptr^);
  2323.           END;
  2324.           IF icon=NIL THEN
  2325.             clock := d.Lock("C:",d.sharedLock);
  2326.             SYS.SETREG(0,d.CurrentDir(clock));
  2327.             icon := GetDiskObject(nameptr^);
  2328.           END;
  2329.         END;
  2330.         ParseIcon(icon);
  2331.       END;
  2332.     END; (* IF iconBase#NIL *)
  2333.  
  2334.     IF wbm.numArgs >= 2 THEN
  2335.       ArgPtr := wbm.argList^[1].name; Name := ArgPtr^;
  2336.       SYS.SETREG(0,d.CurrentDir(wbm.argList^[1].lock));
  2337.     ELSE
  2338.       SYS.SETREG(0,d.CurrentDir(wbm.argList^[0].lock));
  2339.       FileReq(Name)
  2340.     END;
  2341.     IF clock # NIL THEN d.UnLock(clock) END;
  2342.  
  2343.   ELSE (* CLI started *)
  2344.  
  2345.     stdin := (Me.cis # Me.cli.standardInput); (* Input redirected? *)
  2346.  
  2347.     IF iconBase # NIL THEN
  2348.       progdir := d.GetProgramDir();
  2349.       IF progdir = NIL THEN
  2350.         progdir := d.Lock("C:",d.sharedLock); cLocked := w;
  2351.       END;
  2352.       oldcd := d.CurrentDir(progdir);
  2353.       IF d.GetProgramName(Name,LEN(Name)) THEN
  2354.         nameptr := SYS.VAL(e.APTR,d.FilePart(Name));
  2355.         icon := GetDiskObject(nameptr^);
  2356.         ParseIcon(icon);
  2357.         Name[0] := 0X;
  2358.       END;
  2359.       oldcd := d.CurrentDir(oldcd);
  2360.       IF cLocked THEN d.UnLock(progdir) END;
  2361.     END;
  2362.  
  2363.     rd := d.ReadArgs("B=PLANES/N/K,C=PALETTE/K,D=DISPMODEREQ/S,E=EDITOR/K,F=FONT/K,I=INTERLEAVED/S,O=OLDSTYLE/S,P=TOOLPRI/N/K,Q=FASTQUIT/S,S=SCROLLMODE/N/K,T=TABWIDTH/N/K,U=PUBSCREEN/K,X=EXTRASPACE/N/K,W=WINDOW/S,WL=LEFTEDGE/N/K,WT=TOPEDGE/N/K,WW=WIDTH/N/K,WH=HEIGHT/N/K,FW=FRWIDTH/N/K,FH=FRHEIGHT/N/K,FILE",args,NIL);
  2364.     IF rd=NIL THEN
  2365.       SYS.SETREG(0,d.PrintFault(d.IoErr(),NIL));
  2366.       HALT(d.warn)
  2367.     END;
  2368.     IF args.b # NIL THEN depth := SHORT(args.b^) END;
  2369.     IF args.c # NIL THEN COPY(args.c^,Pens) END;
  2370.     IF args.d # NIL THEN modeReq := w END;
  2371.     IF args.e # NIL THEN COPY(args.e^,editcmd) END;
  2372.     IF args.f # NIL THEN COPY(args.f^,FontName) END;
  2373.     IF args.i # NIL THEN interleaved := w END;
  2374.     IF args.o # NIL THEN oldstyle := w END;
  2375.     IF args.q # NIL THEN fastquit := w END;
  2376.     IF args.p # NIL THEN taskpri := SHORT(SHORT(args.p^)) END;
  2377.     IF args.s # NIL THEN scrollmode := SHORT(args.s^) END;
  2378.     IF args.t # NIL THEN tabw := SHORT(args.t^) END;
  2379.     IF args.u # NIL THEN COPY(args.u^,pubscreenname) END;
  2380.     IF args.x # NIL THEN spacing := SHORT(args.x^) END;
  2381.     IF args.w # NIL THEN win := w END;
  2382.  
  2383.     IF args.wl # NIL THEN left  := SHORT(args.wl^) END;
  2384.     IF args.wt # NIL THEN top   := SHORT(args.wt^) END;
  2385.     IF args.ww # NIL THEN width := SHORT(args.ww^) END;
  2386.     IF args.wh # NIL THEN height:= SHORT(args.wh^) END;
  2387.  
  2388.     IF args.fw # NIL THEN frwidth := SHORT(args.fw^) END;
  2389.     IF args.fh # NIL THEN frheight:= SHORT(args.fh^) END;
  2390.  
  2391.     IF args.file # NIL THEN COPY(args.file^,Name); stdin := f END;
  2392.     d.FreeArgs(rd); rd := NIL;
  2393.   END;
  2394.  
  2395.   IF pubscreenname # "" THEN
  2396.     win := w;
  2397.   END;
  2398.  
  2399.   IF taskpri # oldpri THEN SYS.SETREG(0,e.SetTaskPri(Me,taskpri)) END;
  2400.  
  2401.   IF tabw < 1 THEN tabw := 1 END;
  2402.  
  2403.   IF depth < 1 THEN depth := 1 END;
  2404.   IF depth > 2 THEN depth := 2 END;
  2405.  
  2406.   IF str.Occurs(editcmd,"%s")<0 THEN str.Append(editcmd,' "%s"') END;
  2407.  
  2408.   IF FontName # "" THEN
  2409.     i := 0;
  2410.     j := SHORT(str.Length(FontName));
  2411.     LOOP
  2412.       IF i >= j THEN EXIT END;
  2413.       IF FontName[i]='/' THEN
  2414.         FontName[i] := 0X;
  2415.         FontSize := SHORT(StrToInt(SYS.ADR(FontName[i+1]),10));
  2416.         j := i;
  2417.         EXIT
  2418.       END;
  2419.       INC(i);
  2420.     END;
  2421.     IF j<LEN(FontName)-6 THEN
  2422.       e.CopyMem(".font",FontName[j],6);
  2423.     END;
  2424.   END;
  2425.  
  2426.   IF Pens # "" THEN
  2427.     ci := 0;
  2428.     chptr := SYS.ADR(Pens);
  2429.     Pens[LEN(Pens)-1] := 0X;
  2430.     LOOP
  2431.       Cols[ci] := SHORT(StrToInt(SYS.VAL(StringPtr,chptr),16));
  2432.       INC(ci); IF ci=4 THEN EXIT END;
  2433.       WHILE (chptr^#0X) & (chptr^#",") DO
  2434.         chptr:=SYS.VAL(e.APTR,SYS.VAL(LONGINT,chptr)+1)
  2435.       END;
  2436.       IF chptr^="," THEN
  2437.         chptr:=SYS.VAL(e.APTR,SYS.VAL(LONGINT,chptr)+1)
  2438.       ELSE
  2439.         EXIT
  2440.       END;
  2441.     END;
  2442.   END;
  2443.  
  2444.   IF FontSize>50 THEN FontSize := 50 END;
  2445.   IF FontSize< 5 THEN FontSize :=  5 END;
  2446.  
  2447.   IF spacing< 0 THEN spacing :=  0 END;
  2448.   IF spacing>20 THEN spacing := 20 END;
  2449.  
  2450.   IF width <150 THEN width  := 150 END;
  2451.   IF height< 70 THEN height :=  70 END;
  2452.  
  2453.   IF modeReq THEN
  2454.     IF ScreenModeReq(id) THEN
  2455.       SavePrefs(w);
  2456.     END;
  2457.   END;
  2458.  
  2459. (*------  Open File:  ------*)
  2460.  
  2461.   IF stdin THEN
  2462.     MyFile := d.Input();
  2463.     Name := "STDIN";
  2464.   ELSE
  2465.     LOOP
  2466.       MyFile := d.Open(Name,d.oldFile);
  2467.       IF MyFile#NIL THEN EXIT END;
  2468.       FileReq(Name)
  2469.     END;
  2470.   END;
  2471.  
  2472. (*------  Open Screen:  ------*)
  2473.  
  2474.   IF ~win THEN
  2475.  
  2476.     LOOP
  2477.   
  2478.       IF id=g.invalidID THEN
  2479.         id := g.defaultMonitorID;
  2480.         pub := I.LockPubScreen(NIL);
  2481.         IF pub # NIL THEN
  2482.           id := g.GetVPModeID(SYS.ADR(pub.viewPort));
  2483.           I.UnlockPubScreen(NIL,pub);
  2484.         END;
  2485.       END;
  2486.   
  2487.       IF g.GetDisplayInfoData(NIL,dims,SIZE(dims),g.dtagDims,id) > 0 THEN
  2488.         width  := dims.txtOScan.maxX - dims.txtOScan.minX + 1;
  2489.         height := dims.txtOScan.maxY - dims.txtOScan.minY + 1;
  2490.   
  2491.         IF g.GetDisplayInfoData(NIL,disp,SIZE(disp),g.dtagDisp,id) > 0 THEN
  2492.           lace := g.isLace IN disp.propertyFlags;
  2493.           Scrollable := (g.isDraggable IN disp.propertyFlags) & (scrollmode # 3);
  2494.           IF Scrollable THEN INC(height,height) END;
  2495.   
  2496.           Screen := I.OpenScreenTagsA(NIL,
  2497.                                      I.saLeft,       0,
  2498.                                      I.saTop,        0,
  2499.                                      I.saWidth,      width,
  2500.                                      I.saHeight,     height,
  2501.                                      I.saDepth,      depth,
  2502.                                      I.saDisplayID,  id,
  2503.                                      I.saInterleaved,SYS.VAL(SHORTINT,interleaved),
  2504.                                      I.saOverscan,   I.oScanText,
  2505.                                      I.saPens,       SYS.ADR("\xFF\xFF"),
  2506.                                      I.saQuiet,      I.LTRUE,
  2507.                                      u.done);
  2508.         END;
  2509.       END;
  2510.   
  2511.       IF Screen # NIL THEN EXIT END;
  2512.   
  2513.       DEC(depth);
  2514.       IF depth=0 THEN Error(LocStr(MSGCOS)^) END;
  2515.     END;
  2516.   
  2517.     rp := SYS.ADR(Screen.rastPort);
  2518.     BM := rp.bitMap;
  2519.     ri := Screen.viewPort.rasInfo;
  2520.  
  2521.     IF ci>0 THEN g.LoadRGB4(SYS.ADR(Screen.viewPort),Cols,ci) END;
  2522.   
  2523.     left := 0;
  2524.     top  := 0;
  2525.     width  := Screen.width;
  2526.     height := Screen.height;
  2527.  
  2528.   END;
  2529.  
  2530. (*------  Open Window:  ------*)
  2531.  
  2532.   IF win THEN
  2533.  
  2534.     IF pubscreenname="" THEN pub := I.LockPubScreen(NIL);
  2535.                         ELSE pub := I.LockPubScreen(pubscreenname) END;
  2536.     IF pub # NIL THEN
  2537.  
  2538.       zoomBox[0] := left;
  2539.       zoomBox[1] := top;
  2540.       zoomBox[2] := 200;
  2541.       zoomBox[3] := pub.barHeight+1;
  2542.  
  2543.       Window := I.OpenWindowTagsA(NIL,
  2544.                                   I.waTitle,    SYS.ADR(MuchText),
  2545.                                   I.waLeft,     left,
  2546.                                   I.waTop,      top,
  2547.                                   I.waWidth,    width,
  2548.                                   I.waHeight,   height,
  2549.                                   I.waPubScreen,pub,
  2550.                                   I.waIDCMP,    MyIdcmp,
  2551.                                   I.waFlags,    LONGSET{I.windowDrag,I.windowClose,I.windowDepth,I.rmbTrap,I.activate,I.noCareRefresh},
  2552.                                   I.waZoom,     SYS.ADR(zoomBox),
  2553.                                   u.done);
  2554.       I.UnlockPubScreen(NIL,pub);
  2555.     END;
  2556.  
  2557.   ELSE
  2558.  
  2559.     Window := I.OpenWindowTagsA(NIL,
  2560.                                 I.waLeft,    0,
  2561.                                 I.waTop,     10,
  2562.                                 I.waWidth,   width,
  2563.                                 I.waHeight,  height-10,
  2564.                                 I.waCustomScreen,Screen,
  2565.                                 I.waIDCMP,   MyIdcmp,
  2566.                                 I.waFlags,   LONGSET{I.rmbTrap,I.activate,I.borderless,I.noCareRefresh,I.simpleRefresh,I.backDrop},
  2567.                                 u.done);
  2568.   END;
  2569.  
  2570.   IF Window=NIL THEN Error(LocStr(MSGCOW)^) END;
  2571.   initialheight := Window.height;
  2572.  
  2573.   IF win THEN
  2574.     rp := Window.rPort;
  2575.     left   := Window.borderLeft; top    := Window.borderTop;
  2576.     width  := Window.gzzWidth;   height := Window.gzzHeight;
  2577.     Scrollable := f;
  2578.  
  2579.     IF depth < rp.bitMap.depth THEN
  2580.       IF g.base.libNode.version >= 39 THEN g.SetMaxPen(rp,ASH(LONG(1),depth)-1)
  2581.                                       ELSE rp.mask := SHORTSET{0..depth-1}   END;
  2582.     END;
  2583.  
  2584.   END;
  2585.  
  2586. (*------  Open Font:  ------*)
  2587.  
  2588.   IF FontName[0] # 0X THEN
  2589.     MyAttr.name := SYS.ADR(FontName);
  2590.     MyAttr.ySize := FontSize;
  2591.     diskFontBase := e.OpenLibrary("diskfont.library",0);
  2592.     IF diskFontBase # NIL THEN MyFont := OpenDiskFont(MyAttr) END;
  2593.     IF (MyFont # NIL) & ~(g.proportional IN MyFont.flags) THEN g.SetFont(rp,MyFont) END;
  2594.   END;
  2595.  
  2596.   LOOP
  2597.     fontWidth  := rp.font.xSize;
  2598.     fontHeight := rp.font.ySize;
  2599.     IF (fontWidth<=80) & (fontHeight<=80) & (fontWidth>=4) & (fontHeight>=4) THEN EXIT END;
  2600.     MyAttr.name := SYS.ADR("topaz.font");
  2601.     MyAttr.ySize := 8;
  2602.     MyFont := g.OpenFont(MyAttr);
  2603.     IF MyFont=NIL THEN HALT(d.fail) END;
  2604.     g.SetFont(rp,MyFont);
  2605.   END;
  2606.   INC(fontHeight,spacing);               (* extra spacing *)
  2607.   fontBaseLine := rp.font.baseline;
  2608.  
  2609.   NumColumns := width DIV fontWidth;
  2610.   IF Scrollable THEN NumLines   := (height DIV 2) DIV fontHeight;
  2611.                 ELSE NumLines   := height DIV fontHeight; END;
  2612.   PageHeight := fontHeight*NumLines;
  2613.   height :=     PageHeight;
  2614.  
  2615.   ClearDisplay;
  2616.  
  2617.   IF Scrollable THEN
  2618.     Screen.height := height;
  2619.     I.OldMakeScreen(Screen);
  2620.     I.OldRethinkDisplay;
  2621.   ELSIF win THEN
  2622.     INC(top,(Window.gzzHeight-height) DIV 2);
  2623.   END;
  2624.  
  2625. (*------  Get KeyMap:  ------*)
  2626.  
  2627.   IF e.OpenDevice("console.device",-1,conreq,LONGSET{})#0 THEN HALT(d.fail) END;
  2628.   console := conreq.device;
  2629.   con.base := console;
  2630. (*ievent.nextEvent := NIL;
  2631.   ievent.qualifier := {};
  2632.   ievent.eventAddress := NIL; *)
  2633.   ievent.class := ie.rawkey;
  2634.  
  2635.   FOR i := 0 TO 3FH DO
  2636.     ievent.code := i;
  2637.     SYS.SETREG(0,con.RawKeyConvert(ievent,KeyMap[i],16,NIL));
  2638.   END;
  2639.  
  2640. (*------  Decrunch:  ------*)
  2641.  
  2642.   Decrunch;
  2643.  
  2644. (*------  Init & Add 2nd Task:  ------*)
  2645.  
  2646.   ShowTask.spLower := ShowStack;
  2647.   ShowTask.spUpper := SYS.VAL(e.APTR,SYS.VAL(LONGINT,ShowStack) + ShowStackSize);
  2648.   ShowTask.spReg   := ShowTask.spUpper;
  2649.   ShowTask.node.type := e.task;
  2650.   ShowTask.node.name := SYS.ADR("muchmore show task");
  2651.   ShowTask.node.pri  := Me.task.node.pri+1;
  2652.   (* $IF SmallData *)
  2653.   ShowTask.userData  := SYS.REG(13);           (* VarBase *)
  2654.   (* $END *)
  2655.  
  2656.   e.Forbid;
  2657.    e.AddTask(ShowTask,ShowProc,NIL);
  2658.    ShowTaskRunning := w;
  2659.   e.Permit;
  2660.  
  2661.   SYS.SETREG(0,e.Wait(mySig));
  2662.  
  2663. (*------  Main Load / Display Loop:  ------*)
  2664.  
  2665.   LOOP
  2666.     fg := 1; bg := 0; oldfg := fg; oldbg := bg; style := SHORTSET{};
  2667.     RQLen := -1; RQPos := -1;
  2668.     AnzLines := 1;
  2669.     LastLine := FirstLine;
  2670.     BottomLine := FirstLine;
  2671.     TopLine    := FirstLine;
  2672.     TextLength := 0;
  2673.     ReadLength := 0;
  2674.     FindLine   := NIL;
  2675.     FOR i := 0 TO 9 DO TextMarkers[i] := NIL END;
  2676.  
  2677.     FileLength := 0;
  2678.  
  2679.     IF ~stdin THEN
  2680.       MyLock := d.Lock(Name,d.sharedLock);
  2681.       IF MyLock # NIL THEN
  2682.         IF d.Examine(MyLock,FileInfo^) THEN FileLength := FileInfo.size END;
  2683.         d.UnLock(MyLock); MyLock := NIL;
  2684.         IF FileLength=0 THEN Error(LocStr(MSGEMPTY)^) END;
  2685.       END;
  2686.     END;
  2687.  
  2688.     (*------  Start displaying & Loading:  ------*)
  2689.  
  2690.     NewDisp := w;
  2691.  
  2692.     e.Signal(ShowTask,showSig);
  2693.  
  2694.     REPEAT
  2695.       LoadLine := GetTextLine();
  2696.       IF LoadLine=NIL THEN
  2697.         IF ~stdin THEN d.OldClose(MyFile) END;
  2698.         MyFile := NIL;
  2699.       ELSE
  2700.         LoadLine.prev := LastLine;
  2701.         LastLine.next := LoadLine;
  2702.         LastLine := LoadLine;
  2703.       END;
  2704.       IF SignalNewData THEN e.Signal(ShowTask,showSig) END;
  2705.     UNTIL (MyFile=NIL) OR Done OR NewText;
  2706.     IF SignalAllRead THEN e.Signal(ShowTask,showSig) END;
  2707.     REPEAT
  2708.       SYS.SETREG(0,e.Wait(mySig));
  2709.       IF print THEN
  2710.         in  := d.Open("NIL:",d.newFile);
  2711.         IF d.SystemTags(PStr,d.sysInput,    SYS.VAL(e.APTR,in),
  2712.                              d.sysOutput,   NIL,
  2713.                              d.sysAsynch,   d.DOSTRUE,
  2714.                              d.sysUserShell,d.DOSTRUE,
  2715.                              u.done)                   = -1 THEN
  2716.           d.OldClose(in);
  2717.         ELSE
  2718.           Decrunched := f; INC(meInt);
  2719.         END;
  2720.         in := NIL;
  2721.         print := f;
  2722.       END;
  2723.       IF save THEN
  2724.         in := d.Open(Name,d.oldFile);
  2725.         IF in=NIL THEN I.DisplayBeep(NIL) ELSE
  2726.           ol.New(buffer,savesize);
  2727.           SYS.SETREG(0,d.Seek(in,savefrom,0));
  2728.           IF d.Read(in,buffer^,savesize) # savesize THEN
  2729.             I.DisplayBeep(NIL);
  2730.             d.OldClose(in); in := NIL;
  2731.           ELSE
  2732.             d.OldClose(in); in := NIL;
  2733.             IF copy THEN
  2734.               iff := NIL;
  2735.               LOOP
  2736.                 IF ip.base=NIL THEN EXIT END;
  2737.                 iff := ip.AllocIFF();
  2738.                 IF iff=NIL THEN EXIT END;
  2739.                 iff.stream := SYS.VAL(LONGINT,ip.OpenClipboard(0));
  2740.                 IF iff.stream=NIL THEN EXIT END;
  2741.                 ip.InitIFFasClip (iff);
  2742.                 IF (ip.OpenIFF  (iff, ip.write) = 0) &
  2743.                    (ip.PushChunk(iff, SYS.VAL(LONGINT,"FTXT"), ip.idFORM, ip.sizeUnknown)=0) &
  2744.                    (ip.PushChunk(iff, 0, SYS.VAL(LONGINT,"CHRS"), ip.sizeUnknown)=0) &
  2745.                    (ip.WriteChunkBytes(iff,buffer^,savesize) = savesize) &
  2746.                    (ip.PopChunk (iff)=0) &
  2747.                    (ip.PopChunk (iff)=0) THEN
  2748.                 END;
  2749.                 EXIT;
  2750.               END;
  2751.               IF iff # NIL THEN
  2752.                 ip.CloseIFF(iff);
  2753.                 IF iff.stream#0 THEN ip.CloseClipboard (SYS.VAL(e.APTR,iff.stream)) END;
  2754.                 ip.FreeIFF (iff);
  2755.               END;
  2756.             ELSE
  2757.               out := d.Open(WriteName,d.oldFile);
  2758.               IF out=NIL THEN
  2759.                 out := d.Open(WriteName,d.newFile);
  2760.               ELSE
  2761.                 SYS.SETREG(0,d.Seek(out,0,d.end));
  2762.               END;
  2763.               IF out=NIL THEN I.DisplayBeep(NIL) ELSE
  2764.                 IF d.Write(out,buffer^,savesize)#savesize THEN I.DisplayBeep(NIL) END;
  2765.                 d.OldClose(out); out := NIL;
  2766.               END;
  2767.             END;
  2768.           END;
  2769.           DISPOSE(buffer);
  2770.         END;
  2771.         save := f;
  2772.       END;
  2773.       IF Done THEN EXIT END;
  2774.     UNTIL NewText;
  2775.     IF MyFile # NIL THEN
  2776.       IF ~stdin THEN d.OldClose(MyFile) END;
  2777.       MyFile := NIL
  2778.     END;
  2779.     IF Decrunched & d.DeleteFile(Name) THEN END;
  2780.     Decrunched := f;
  2781.     DisposeLines();
  2782.     FirstLine.next := NIL; NewText := f;
  2783.     Name := OldName;
  2784.     stdin := FALSE;
  2785.     REPEAT
  2786.       FileReq(Name);
  2787.       MyFile := d.Open(Name,d.oldFile);
  2788.     UNTIL MyFile # NIL;
  2789.     Decrunch;
  2790.   END;   (* LOOP *)
  2791.  
  2792. CLOSE
  2793.  
  2794.   IF Window      # NIL THEN Window.userPort.sigTask := Me    END;
  2795.   IF ShowTaskRunning   THEN e.RemTask(ShowTask)              END;
  2796.   IF console     # NIL THEN e.CloseDevice(conreq)            END;
  2797.   IF Window      # NIL THEN I.CloseWindow(Window)            END;
  2798.   IF Screen      # NIL THEN I.OldCloseScreen(Screen)         END;
  2799.   IF MyFont      # NIL THEN g.CloseFont(MyFont)              END;
  2800.   IF (MyFile#NIL) & ~stdin THEN d.OldClose(MyFile)           END;
  2801.   IF in          # NIL THEN d.OldClose(in)                   END;
  2802.   IF out         # NIL THEN d.OldClose(out)                  END;
  2803.   IF Decrunched        THEN SYS.SETREG(0,d.DeleteFile(Name)) END;
  2804.   IF xpk         # NIL THEN e.CloseLibrary(xpk)              END;
  2805.   IF asl         # NIL THEN e.CloseLibrary(asl)              END;
  2806.   IF diskFontBase# NIL THEN e.CloseLibrary(diskFontBase)     END;
  2807.   IF iconBase    # NIL THEN e.CloseLibrary(iconBase)         END;
  2808.   IF mySigBit >= 0     THEN e.FreeSignal(mySigBit)           END;
  2809.   IF catalog     # NIL THEN loc.CloseCatalog(catalog);       END;
  2810.   IF taskpri # oldpri  THEN oldpri := e.SetTaskPri(Me,oldpri)END;
  2811.   OldDir := d.CurrentDir(OldDir);
  2812.  
  2813. END MuchMore.
  2814.  
  2815.